traverse_ is:exact
base Data.Foldable,
protolude Protolude,
relude Relude.Foldable.Reexport,
base-prelude BasePrelude,
Cabal-syntax Distribution.Compat.Prelude,
numhask NumHask.Prelude,
ghc-internal GHC.Internal.Data.Foldable,
rebase Rebase.Prelude,
quaalude Essentials,
xmonad-contrib XMonad.Prelude,
incipit-base Incipit.Foldable,
cabal-install-solver Distribution.Solver.Compat.Prelude,
faktory Faktory.Prelude,
verset Verset,
calligraphy Calligraphy.Prelude Map each element of a structure to an
Applicative action,
evaluate these actions from left to right, and ignore the results. For
a version that doesn't ignore the results see
traverse.
traverse_ is just like
mapM_, but generalised to
Applicative actions.
Examples
Basic usage:
>>> traverse_ print ["Hello", "world", "!"]
"Hello"
"world"
"!"
Map each element of a structure to an action, evaluate these actions
from left to right, and ignore the results. For a version that doesn't
ignore the results see
traverse.
Visit every node in the given list. If new nodes are appended during
the traversal, they will not be visited. Every live node that was in
the list when the traversal began will be visited exactly once;
however, no guarantee is made about the order of the traversal.
Visit every node in the given list. If new nodes are appended during
the traversal, they will not be visited. Every live node that was in
the list when the traversal began will be visited exactly once;
however, no guarantee is made about the order of the traversal.
Execute, traversing the stream with a side effect in the inner monad.
Map each element of the array to an action, evaluate these actions
from left to right, and ignore the results. For a version that doesn't
ignore the results, see
traverse.
Map each element of a collection to an action, evaluate these actions
from left to right, and ignore the results. For a version that doesn't
ignore the results see
traverse
Map each element to an action, evaluate these actions from left to
right and ignore the results. Note that the return type is
Void
instead of usual
().
>>> traverse_ print (0...) -- hit Ctrl+C to terminate
0
1
2Interrupted
traverse_ could be productive for some short-circuiting
f:
>>> traverse_ (\x -> if x > 10 then Left x else Right ()) (0...)
Left 11
traverse_ :: forall t k l o f a b uk ul . (Foldable t k l, PreArrow k, PreArrow l, Monoidal f l l, Monoidal f k k, ObjectPair l (f ul) (t a), ObjectPair k (f ul) a, ObjectPair l ul (t a), ObjectPair l (t a) ul, ObjectPair k b ul, Object k (f b), ObjectPair k (f ul) (f ul), ObjectPair k ul ul, uk ~ UnitObject k, ul ~ UnitObject l, uk ~ ul) => (a `k` f b) -> t a `l` f ul Despite the ridiculous-looking signature, this is in fact equivalent
to
traverse_ within Hask.
This is generally a faster way to traverse while ignoring the result
rather than using
mapM_.