Deprecate addIndex
and addIndexRight
and update map
, reduce
, etc, signatures
#3413
Closed
Harris-Miller
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
My simplest answer is to read #452 through. You can come back next week when you've finished. 😉 We added The classic example is
because The trouble is that it simply doesn't belong for any input types except arrays, and certain other iterables. It doesn't apply to arbitrary Functors. Just saying that they can ignore it runs afoul our interest in simplicity. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
addIndexRight
was added in0.29.0
and is missing typing for it intypes-ramda
. Looking into howaddIndex
works, I couldn't help but notice that it doesn't seem necessary. AlladdIndex
does is override calling the callback function withidx
andlist
as the second and third parameter.This begs the question, why can't this be the default behavior for
map
,reduce
, etc?While optional properties like this are not very FP, I think this case is different. The callback functions can always be called with the additional parameters, as they would only apply to the function passed if that function utilized them. This is how
Array#map
, etc, work natively. I believe the ramda functions for them should work the same.The problem is that
map
, etc, support more than arrays. Personally, I don't think that this is a problem. From a typing perspective, there is nothing wrong with having a specific signature for the callback function depending on the type of the subject (list, object, or functor)Considering how
Object.entries()
yield the[i, value][]
for arrays and[key, value][]
for objects, the implementation for the above would actually be the sameFantasyLand implementations for Functor, Filterable, and the like, the 2nd and 3rd arguments would simply not apply.
I would also argue that we would not need to worry that
map
would take a function that could not apply correctly to all subject types. The way that a callback function is written would be specific for the subject type. Callback functions passed that only accept one argument would apply to all, while more than one would only apply to arrays and object. This is effectively the concept of wrapping withaddIndex
, simply without the extra step. I don't think it is unreasonable behavior for an overloaded function such asmap
andfilter
.Was hoping to get some feedback on this idea from core team members
Beta Was this translation helpful? Give feedback.
All reactions