3 ms·
The map function fully expects a function with two arguments, as per documentation. Why would passing a function that takes two arguments to map be an error?
by pennaMan 7y ago
The map function fully expects a function with two arguments, as per documentation. Why would passing a function that takes two arguments to map be an error?
- benschulz 7y agoThe example given is taken from Rust. Rust does not allow overloading (even in terms of optional parameters, I believe). Well, Rust allows overloading by implementing different traits but then forces you to disambiguate where necessary.
- estebank 7y agoThe map function has a bad API surface that interacts poorly with the way people expect it to work. In a better designed API, if you needed the index of each yielded value other languages have some kind of enumerate method that will allow people opt-in to getting the index. Then if you needed the replicate the presented situation you would have something like ['1', '7', '11'].enumerate().map(([val, idx]) => parseInt(val, idx)) I understand that this pattern of having extra "helper" arguments is pervasive in JS and might seem less exotic to the community, but I feel it is a problematic approach, as it is foot-gun prone.
- deleted 7y ago[deleted]