-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Background and motivation
From the requirements point of view: the fold function must provide init, reduce does not require init, which means no longer needs to write boilerplate "match with" code like "extract the first element from generic Collections as init, the remaining elements as sequence, and then pass it to fold".
From a reasonable point of view: list/array/seq all provide native reduce methods, list/array also provides native reduceBack methods. This generic encapsulation is not difficult to implement, and other languages (except fundamental FPs like Haskell) generally provide reduce methods, which is reasonable.
I know there is a reduce function implementation now, but that one is very difficult to use. To be honest, I have no idea how to pass parameters.
API Proposal
let inline reduce (folder: 'State->'T->'State) (foldable: '``Foldable<'T>``) : 'State
let inline reduceBack (folder: 'T->'State->'State) (foldable: '``Foldable<'T>``) : 'State
API Usage
reduce (*) [1; 2; 3; 4; 5] |> should equal 120
reduce (+) ([]: int list) // throws an exception
Alternative Designs
No response
Risks
No response
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
Yes, please assign this issue to me.