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

foldr1 and foldl1 are too restrictive

Open natefaubion opened this issue 2 years ago • 1 comments

Should the signature of foldr1 (and similarly foldl1) be:

foldr1 :: forall f a b. Foldable1 f => (a -> b -> b) -> (a -> b) -> f a -> b

I understand the logic behind the current signature:

foldr1 :: forall f a b. Foldable1 f => (b -> b -> b) -> f b -> b

In that, if I have a mapping from a -> b, then I can pre-map unconditionally, and derive the latter signature. Unfortunately that's not actually what I want to do:

  • I only want the mapping to apply to the terminal value.
  • I want to otherwise combine with the combining function.
  • I don't want to waste an entire traversal to make the signature work.

I feel like there's a missed opportunity with the current signature. To be honest, I almost never want the current signature.

natefaubion avatar May 16 '22 20:05 natefaubion

I'd be ok with making a breaking change release outside of the compiler changes. However, how would that be handled?

JordanMartinez avatar May 17 '22 22:05 JordanMartinez