Giter VIP home page Giter VIP logo

Comments (3)

CrossEye avatar CrossEye commented on June 15, 2024

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.

buzzdecafe avatar buzzdecafe commented on June 15, 2024

also, there are real use cases where having the index is very helpful, e.g. working with 2D array

from ramda.

ceymard avatar ceymard commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.