elm-community / list-extra

Convenience functions for working with List.
http://package.elm-lang.org/packages/elm-community/list-extra/latest
MIT License
135 stars 59 forks source link

foldl1/foldr1 should use descriptive names as the '1' imparts no information #15

Open OvermindDL1 opened 8 years ago

OvermindDL1 commented 8 years ago

As requested by @jvoigtlaender this issue has been opened to propose changing the names (or at the very least aliasing the names to new names) of foldl1->reducel and foldr1->reducer or some variant there-of.

Immediate languages that come to mind that use this pattern are:

And I just found a document on wikipedia: https://en.wikipedia.org/wiki/Fold_(higher-order_function)#Folds_in_various_languages

On the above wikipedia list Haskell is the only language that uses foldl1 and foldr1, the general usage among the rest of the languages are various usages of reduce such as reducel/reducer, reduce_l/reduce_r, reduce_l/reduce_r, reduce/reduce_r, reduce/reduce_right and so forth with them using either another variant of reduce or using foldl/foldr to handle the Elm List.foldl and List.foldr style functions.

As seen reduce is used almost exclusively in languages that have a reduce/fold?1 style function, and both reduce and fold are used fairly evenly for fold style functionality depending on whether the language has default currying (like F# and Elm languages are) or whether the arity is part of the function definition (like Clojure or Elixir).

Thus to maintain consistency with the rest of near the entire functional ecosystem List.Extra.foldl1 and List.Extra.foldr1 should be at most renamed or at least aliased with List.Extra.reducel and List.Extra.reducer or some variant there-of as it is both more descriptive and functional language standard.

jvoigtlaender commented 8 years ago

Just for the record: I didn't request opening this issue because I endorse the proposal, I just requested it so that important information is all together in an opening comment, not in a long (previous) discussion thread.

Mouvedia commented 7 years ago

It should probably be camelcased though.

reduceL / reduceR

@OvermindDL1 https://rosettacode.org/wiki/Catamorphism

prikhi commented 7 years ago

I like reduceL or reduceLeft