Open OvermindDL1 opened 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.
It should probably be camelcased though.
reduceL / reduceR
@OvermindDL1 https://rosettacode.org/wiki/Catamorphism
I like reduceL
or reduceLeft
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
andfoldr1
->reducer
or some variant there-of.Immediate languages that come to mind that use this pattern are:
reduce
==List.Extra.foldl1
,fold
==List.foldl
):reduce
==List.Extra.foldl1
,reduce_from
==List.foldl
):reduce
==List.Extra.foldl1
,fold
==List.foldl
):reduce
for both thereduce
andfold
variants, depending on whether an accumulator was passed or not.reduce
==List.Extra.foldl1
,foldl
==List.foldl
):List.foldl
was a hold-over from erlang whereEnum.reduce
was added by Elixir itself, hence the different type signatures, they can both work over enumerables though once properly massaged.Enum.reduce/2
andEnum.reduce/3
are both supplied, howeverEnum.reduce/3
delegates toList.foldl/3
in the majority of cases.reduceLeft
==List.Extra.foldl1
,foldLeft
==List.foldl
):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
andfoldr1
, the general usage among the rest of the languages are various usages ofreduce
such asreducel
/reducer
,reduce_l
/reduce_r
,reduce_l
/reduce_r
,reduce
/reduce_r
,reduce
/reduce_right
and so forth with them using either another variant ofreduce
or usingfoldl
/foldr
to handle the ElmList.foldl
andList.foldr
style functions.As seen
reduce
is used almost exclusively in languages that have areduce
/fold?1
style function, and bothreduce
andfold
are used fairly evenly forfold
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
andList.Extra.foldr1
should be at most renamed or at least aliased withList.Extra.reducel
andList.Extra.reducer
or some variant there-of as it is both more descriptive and functional language standard.