Skip to content

Commit b5a26df

Browse files
committed
add example for rtraverse
1 parent bf3bfa3 commit b5a26df

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Data/Vinyl/Core.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,23 @@ instance RecApplicative rs => RecApplicative (r ': rs) where
319319
rpure s = s :& rpure s
320320
{-# INLINE rpure #-}
321321

322-
-- | A record may be traversed with respect to its interpretation functor. This
323-
-- can be used to yank (some or all) effects from the fields of the record to
324-
-- the outside of the record.
322+
{- |
323+
A record may be traversed with respect to its interpretation functor. This
324+
can be used to yank (some or all) effects from the fields of the record to
325+
the outside of the record.
326+
327+
>>> import Data.Vinyl.Functor (Identity(Identity))
328+
>>> testRec :: Rec Maybe '[String, Double, Int] = Just "Ho" :& Just 3.0 :& Nothing :& RNil
329+
>>>
330+
:{
331+
ext :: Maybe x -> Maybe (Identity x)
332+
ext (Just x) = Just (Identity x)
333+
ext Nothing = Nothing
334+
:}
335+
>>> rtraverse ext testRec
336+
Nothing
337+
-}
338+
325339
rtraverse
326340
:: Applicative h
327341
=> (forall x. f x -> h (g x))

0 commit comments

Comments
 (0)