funcadelic.js icon indicating copy to clipboard operation
funcadelic.js copied to clipboard

Make Foldable callback signatures consistent

Open taras opened this issue 7 years ago • 2 comments

Callbacks for foldl or foldr have different argument signature for objects and arrays. For example, foldl(fn, 0, [1, 2, 3]) will invoke the callback with 0, 1, where 0 is the initial value and memo is 1. Doing the same with an object { 1:1, 2:2, 2:3 } will send 0, { key: "1", value: 1 }.

This gets awkward when your application might invoke the fold on an array or object because the callback has to check the type of the original object to know what call signature to expect.

I propose that we change the array signature to match that of the object. It'll require changing all places where the folds are used. Considering that we're still pre 1.0, we can make these changes.

taras avatar May 29 '18 17:05 taras

We should also consider making the Functor uniform.

cowboyd avatar May 29 '18 17:05 cowboyd

The callbacks for Functor are very similar. One difference I see is that array functor eager, unlike object functor. What specifically are you referring to?

taras avatar May 29 '18 18:05 taras