Skip to content

Commit 178761f

Browse files
committed
add example for rtraverseIn
1 parent b5a26df commit 178761f

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Data/Vinyl/Core.hs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ ext Nothing = Nothing
335335
>>> rtraverse ext testRec
336336
Nothing
337337
-}
338-
339338
rtraverse
340339
:: Applicative h
341340
=> (forall x. f x -> h (g x))
@@ -345,13 +344,28 @@ rtraverse _ RNil = pure RNil
345344
rtraverse f (x :& xs) = (:&) <$> f x <*> rtraverse f xs
346345
{-# INLINABLE rtraverse #-}
347346

348-
-- | While 'rtraverse' pulls the interpretation functor out of the
349-
-- record, 'rtraverseIn' pushes the interpretation functor in to each
350-
-- field type. This is particularly useful when you wish to discharge
351-
-- that interpretation on a per-field basis. For instance, rather than
352-
-- a @Rec IO '[a,b]@, you may wish to have a @Rec Identity '[IO a, IO
353-
-- b]@ so that you can evaluate a single field to obtain a value of
354-
-- type @Rec Identity '[a, IO b]@.
347+
{- |
348+
While 'rtraverse' pulls the interpretation functor out of the
349+
record, 'rtraverseIn' pushes the interpretation functor in to each
350+
field type. This is particularly useful when you wish to discharge
351+
that interpretation on a per-field basis. For instance, rather than
352+
a @Rec IO '[a,b]@, you may wish to have a @Rec Identity '[IO a, IO
353+
b]@ so that you can evaluate a single field to obtain a value of
354+
type @Rec Identity '[a, IO b]@.
355+
356+
>>> import Data.Vinyl.Functor (Identity(Identity))
357+
>>> testRec :: Rec Maybe '[String, Double, Int] = Just "Ho" :& Just 3.0 :& Nothing :& RNil
358+
>>>
359+
:{
360+
push :: forall x. Maybe x -> Identity (Maybe x)
361+
push (Just x) = Identity (Just x)
362+
push Nothing = Identity Nothing
363+
:}
364+
>>> :t rtraverseIn push testRec
365+
rtraverseIn push testRec
366+
:: Rec Identity '[Maybe [Char], Maybe Double, Maybe Int]
367+
-}
368+
355369
rtraverseIn :: forall h f g rs.
356370
(forall a. f a -> g (ApplyToField h a))
357371
-> Rec f rs

0 commit comments

Comments
 (0)