Closed JAForbes closed 6 years ago
Maybe. I'm not sure. caseOn
should definitely work as a reducer function. But the problem is whether or not a reducer function takes it's accumulator first or last. When doing functional programming I believe a -> b -> b
, i.e. the accumulator last, is most convenient. However that is not the typical order in JavaScript. So maybe is should be changed.
@paldepind That is interesting. Why would accumulator last be more convenient? I am trying to imagine the ramifications of that.
I would argue for that having the accumulator last supports currying in a better fashion.
For what it's worth Haskell's foldl
is of the following type:
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
Exactly. The other argument order is much better for currying, where functions typically take the structure to modify as the last element.
@davidchambers, in Haskell there is foldr
which has the "correct" order. Also, foldr
is more common as far as I'm aware.
In order to use caseOn as a reducer it would be more convenient to have caseOn parameter order reversed.
I noticed in the functional frontend architecture that caseOn is flipped there as well.
I realise this is a breaking change, but I wonder if there some way to solve this, or if there was some reason the arguments were in the other order in the first place.