GithubHelp home page GithubHelp logo

Converge equivalent? about rambda HOT 7 CLOSED

selfrefactor avatar selfrefactor commented on May 22, 2024
Converge equivalent?

from rambda.

Comments (7)

tim-crisp avatar tim-crisp commented on May 22, 2024 1

@selfrefactor I'm interested to find out how you would approach certain problems without the functionality of converge. If for instance I wanted to make sure that every element in an array of scores was an integer, I could write something like this in ramda:

const data = {
  id: 'some_id',
  scores: [0, '4', 10, 'hi']
}

const parseScores =
  R.converge(
    R.assoc,
    [
      R.always('scores'),
      R.compose(
        R.map(
          R.when(
            R.complement(R.is(Number)),
            R.compose(
              R.defaultTo(0),
              parseInt
            )
          )
        ),
        R.pathOr([], ['scores'])
      ),
      R.identity
    ]
  )

parseScores(data); // '{"id": "some_id", "scores": [0, 4, 10, 0]}'

The use of converge with assoc ensures that only the scores property is modified. How would you approach such a problem without the ability to converge?

from rambda.

tim-crisp avatar tim-crisp commented on May 22, 2024 1

Fair enough. I might create a PR in the near future, when I have some time.
Thanks!

from rambda.

selfrefactor avatar selfrefactor commented on May 22, 2024 1

Ok, that would be great. I will keep the issue open for the time being.

from rambda.

selfrefactor avatar selfrefactor commented on May 22, 2024

I left this types of method on purpose out of Rambda's API so there is no converge equivalent.

Rambda idea was to be used by people who find this types of methods as overkill.

Still, if you interested in creating PR with converge method, I'll approve it.

from rambda.

selfrefactor avatar selfrefactor commented on May 22, 2024

I would go with more direct approach and leave FP behind in this case, i.e. I will write stupid explicit code.

from rambda.

MaxSvargal avatar MaxSvargal commented on May 22, 2024

+1, I don't understand how do you live without a kind of methods like converge.
Because of this I can't move from ramda to rambda =(

from rambda.

selfrefactor avatar selfrefactor commented on May 22, 2024

@MaxSvargal Sorry to hear that, but the PR with coverge never arrived and that is why it is still missing in Rambda. As I said above, if PR with this method is submitted, I will gladly accept it.

As for your funny remark about living without converge method - I find myself wanting to write stupider code as it is easier to maintain. converge and other similar methods may be fun to use, but they require very specific mind approach, which not everybody are willing to agree with. We write code not only for our present self, but for our future self as well as for the people reading it. Smart code is great looking, but stupid code has its own beauty with its simpleness.

from rambda.

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.