(question) Folds implementation and reduce()
K900 opened this issue · 4 comments
K900 commented
I want to add foldl and foldr tomorrow, but I feel like this needs some discussion. CPython's builtin reduce() is a left-fold. Can/should we rely on this or should it be replaced with a custom left-fold implementation? reduce() should be faster, but the actual result of it is up to the implementation if I understand correctly.
kachayev commented
Actually, I thought about foldl
, foldr
as about operator. Something like:
>>> from fn import op, _
>>> op.foldl(_ + _)([1,2,3])
6
>>> folder = op.foldr(_ * _, 1)
>>> folder([1,2,3])
6
K900 commented
I like that one. Will update my code before pushing then. Probably tomorrow.
kachayev commented
Ok, thanks for help!
Just link your pull request to this issue.