purescript-foldable-traversable icon indicating copy to clipboard operation
purescript-foldable-traversable copied to clipboard

foldrM

Open mrsekut opened this issue 3 years ago • 3 comments

Is there any reason why there is foldlM (foldM) and there is no foldrM? I was confused because I didn't hit when I searched for this in pursuit.

foldrM :: forall a m b f. Foldable f => Monad m => (a -> b -> m b) -> b -> f a -> m b
foldrM f z0 xs = foldl c pure xs z0
  where c k x z = f x z >>= k

mrsekut avatar Jun 18 '21 17:06 mrsekut

It was probably an oversight?

JordanMartinez avatar Jun 18 '21 19:06 JordanMartinez

I think because nobody has asked for it before, and I think not adding things to the core libraries if there isn't a clear demand for them is generally a good strategy. (That's not to say that we can't add it now, though).

hdgarrood avatar Jun 18 '21 20:06 hdgarrood

There's some discussion in https://github.com/purescript/purescript-foldable-traversable/pull/111.

hdgarrood avatar Jun 18 '21 20:06 hdgarrood