>>> traverse Just [1,2,3,4] Just [1,2,3,4]
>>> traverse id [Right 1, Right 2, Right 3, Right 4] Right [1,2,3,4]In the next examples, we show that Nothing and Left values short circuit the created structure.
>>> traverse (const Nothing) [1,2,3,4] Nothing
>>> traverse (\x -> if odd x then Just x else Nothing) [1,2,3,4] Nothing
>>> traverse id [Right 1, Right 2, Right 3, Right 4, Left 0] Left 0
>>> traverse1Of_ both1 (\ks -> Map.fromList [ (k, ()) | k <- ks ]) ("abc", "bcd") fromList [('b',()),('c',())]
traverse1Of_ :: Apply f => Fold1 s a -> (a -> f r) -> s -> f ()
traverseByOf traverse ≡ traverseBy
>>> traverseOf each print (1,2,3) 1 2 3 ((),(),())
traverseOf ≡ id itraverseOf l ≡ traverseOf l . Indexed itraverseOf itraversed ≡ itraverseThis yields the obvious law:
traverse ≡ traverseOf traverse
traverseOf :: Functor f => Iso s t a b -> (a -> f b) -> s -> f t traverseOf :: Functor f => Lens s t a b -> (a -> f b) -> s -> f t traverseOf :: Apply f => Traversal1 s t a b -> (a -> f b) -> s -> f t traverseOf :: Applicative f => Traversal s t a b -> (a -> f b) -> s -> f t
>>> traverseOf_ both putStrLn ("hello","world") hello world
traverse_ ≡ traverseOf_ folded
traverseOf_ _2 :: Functor f => (c -> f r) -> (d, c) -> f () traverseOf_ _Left :: Applicative f => (a -> f b) -> Either a c -> f ()
itraverseOf_ l ≡ traverseOf_ l . IndexedThe rather specific signature of traverseOf_ allows it to be used as if the signature was any of:
traverseOf_ :: Functor f => Getter s a -> (a -> f r) -> s -> f () traverseOf_ :: Applicative f => Fold s a -> (a -> f r) -> s -> f () traverseOf_ :: Functor f => Lens' s a -> (a -> f r) -> s -> f () traverseOf_ :: Functor f => Iso' s a -> (a -> f r) -> s -> f () traverseOf_ :: Applicative f => Traversal' s a -> (a -> f r) -> s -> f () traverseOf_ :: Applicative f => Prism' s a -> (a -> f r) -> s -> f ()
itraverse ≡ itraverseOf itraversed
itraverseOf ≡ withIndex traverseOf l = itraverseOf l . const = id
itraverseOf :: Functor f => IndexedLens i s t a b -> (i -> a -> f b) -> s -> f t itraverseOf :: Applicative f => IndexedTraversal i s t a b -> (i -> a -> f b) -> s -> f t itraverseOf :: Apply f => IndexedTraversal1 i s t a b -> (i -> a -> f b) -> s -> f t
traverseOf_ l ≡ itraverseOf l . const
itraverseOf_ :: Functor f => IndexedGetter i s a -> (i -> a -> f r) -> s -> f () itraverseOf_ :: Applicative f => IndexedFold i s a -> (i -> a -> f r) -> s -> f () itraverseOf_ :: Functor f => IndexedLens' i s a -> (i -> a -> f r) -> s -> f () itraverseOf_ :: Applicative f => IndexedTraversal' i s a -> (i -> a -> f r) -> s -> f ()