If you are blowing the stack when doing traverse_
over an Array
then you can use this stack-safe traverseRec_
function instead, written in terms of Data.Array.foldRecM
-- | Traverse an `Array`, performing some effects
-- | at each value, ignoring the final result. Stack-safe.
traverseRec_
:: forall m a b
. MonadRec m
=> (a -> m b)
-> Array a
-> m Unit
traverseRec_ f ta = Data.Array.foldRecM (\_ x -> void $ f x) unit ta
I kind of think traverseRec_
should be in a library, but I’m not sure which library.
Who can write traverseRec
in terms of foldRecM
as a stack-safe alternative to traverse
?
-- | Traverse an `Array`, performing some effects
-- | at each value and accumulating the result. Stack-safe.
traverseRec
:: forall m a b
. MonadRec m
=> (a -> m b)
-> Array a
-> m (Array b)