Comments (3)
We are open to discussions about this, certainly. Neither of us loves this solution. But we really prefer that map
not generally pass these unnecessary parameters. It's nothing to do with performance. (We'd get better if we didn't have to deal with this flag, honestly.) But it means that your callback function is generally very simple: function(item) :: item
. And it avoids this sort of problem:
map.idx(parseFloat, ["1.1", "2.2", "3.3"]); //=> [1.1, 2.2, 3.3]
map.idx(parseInt, ["1", "2", "3"]); //=> [1, NaN, NaN] // WTF?
(This has to do with parseInt
interpreting the index
passed by map.idx
as its radix
parameter.)
It can be fixed by not using the additional parameters
map(parseInt, ["1", "2", "3"]); //=> [1, 2, 3]
This is not limited to our implementation. Here is the native version.
["1", "2", "3"].map(parseInt); //=> [1, NaN, NaN]
We simply feel that the main use of map
involves working with the item alone. But we do want to be able to offer a version that also gives you the index and the whole array. That was the point of map.idx
. But we'd love to hear alternatives that allow the simplest case to remain simple.
from ramda.
also, there are real use cases where having the index is very helpful, e.g. working with 2D array
from ramda.
I'm all for having the indexes ! I was advocating for the generalization of its passing to the parameters, but the parseInt
and parseFloat
examples are fairly convincing (even though in those particular cases, knowing that the prototype of these functions accept more arguments, a wrapper could do the trick, but, meh, okay :)
from ramda.
Related Issues (20)
- propEq documentation error HOT 4
- [Bug] groupBy result keys order when 0 as first character HOT 6
- R.pipe(R.tryCatch, ...) anomaly HOT 12
- clone does not clone error instance HOT 2
- swap does not work as intended
- Ramda is 3x slower because it uses the arguments object? HOT 10
- Broken link in the "Install specific functions" section of README
- how to implement insertWhile HOT 2
- R.aperture returns arbitrary/random ordering of "consecutive" elements HOT 1
- 0.29.1 Upgrade Guide HOT 11
- compose does not work with zipwith HOT 2
- R.without broke backwards compatibility on #2603 HOT 1
- update vulnerable dependencies
- update sanctuary
- bug: code coverage failing
- enhancement: update prop to include deeply nested objects
- enhancement: update path to use prop
- Support promises for pipe and pipeWith HOT 2
- illegal invocation HOT 4
- `groupBy` throws inscrutable errors when inferred to be a transducer HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ramda.