Skip to content

Commit

Permalink
Emphasize similarities between traversalVL and foldVL
Browse files Browse the repository at this point in the history
  • Loading branch information
arybczak committed Jun 11, 2021
1 parent 7cc3f9c commit 8f9db98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions optics-core/src/Optics/Fold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,17 @@ import Optics.Internal.Utils
-- | Type synonym for a fold.
type Fold s a = Optic' A_Fold NoIx s a

-- | Obtain a 'Fold' by lifting 'traverse_' like function.
-- | Construct a 'Fold' from a 'traverse_' like function.
--
-- /Note:/ for lifting a 'Data.Traversable.traverse' like function see
-- 'Optics.Traversal.traversalVL'.
--
-- @
-- 'foldVL' '.' 'traverseOf_' ≡ 'id'
-- 'traverseOf_' '.' 'foldVL' ≡ 'id'
-- @
foldVL
:: (forall f. Applicative f => (a -> f u) -> s -> f v)
:: (forall f. Applicative f => (a -> f b) -> s -> f ())
-> Fold s a
foldVL f = Optic (foldVL__ f)
{-# INLINE foldVL #-}
Expand Down
9 changes: 7 additions & 2 deletions optics-core/src/Optics/Traversal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ type TraversalVL s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
-- | Type synonym for a type-preserving van Laarhoven traversal.
type TraversalVL' s a = TraversalVL s s a a

-- | Build a traversal from the van Laarhoven representation.
-- | Construct a 'Traversal' from a 'traverse' like function.
--
-- /Note:/ for lifting a 'Data.Foldable.traverse_' like function see
-- 'Optics.Fold.foldVL'.
--
-- @
-- 'traversalVL' '.' 'traverseOf' ≡ 'id'
-- 'traverseOf' '.' 'traversalVL' ≡ 'id'
-- @
traversalVL :: TraversalVL s t a b -> Traversal s t a b
traversalVL
:: (forall f. Applicative f => (a -> f b) -> s -> f t)
-> Traversal s t a b
traversalVL t = Optic (wander t)
{-# INLINE traversalVL #-}

Expand Down

0 comments on commit 8f9db98

Please sign in to comment.