{-# OPTIONS_HADDOCK not-home #-}

-- | Internal implementation details of traversals.
--
-- This module is intended for internal use only, and may change without warning
-- in subsequent releases.
module Optics.Internal.Traversal where

import Data.Profunctor.Indexed

import Optics.Internal.Optic
import Optics.Internal.Fold
import Optics.Internal.Setter

-- | Internal implementation of 'Optics.Traversal.traversed'.
traversed__
  :: (Traversing p, Traversable f)
  => Optic__ p i i (f a) (f b) a b
traversed__ :: Optic__ p i i (f a) (f b) a b
traversed__ = (forall (f :: * -> *).
 Applicative f =>
 (a -> f b) -> f a -> f (f b))
-> Optic__ p i i (f a) (f b) a b
forall (p :: * -> * -> * -> *) a b s t i.
Traversing p =>
(forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t)
-> p i a b -> p i s t
wander forall (f :: * -> *). Applicative f => (a -> f b) -> f a -> f (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
{-# INLINE [0] traversed__ #-}

-- Because traversed__ inlines late, GHC needs rewrite rules for all cases in
-- order to generate optimal code for each of them. The one that rewrites
-- traversal into a traversal correspond to an early inline.

{-# RULES

"traversed__ -> wander traverse"
  forall (o :: Star g i a b). traversed__ o = wander traverse o
    :: Traversable f => Star g i (f a) (f b)

"traversed__ -> folded__"
  forall (o :: Forget r i a b). traversed__ o = folded__ o
    :: Foldable f => Forget r i (f a) (f b)

"traversed__ -> mapped__"
  forall (o :: FunArrow i a b). traversed__ o = mapped__ o
    :: Functor f => FunArrow i (f a) (f b)

#-}