Skip to content

Reverse argument order #4

Open
Open
@tomhicks-bsf

Description

@tomhicks-bsf

This is quite a big suggestion, but in my opinion the order of the arguments is inconsistent across functions, and generally the wrong way around.

See these for details:
http://functionaltalks.org/2013/05/27/brian-lonsdorf-hey-underscore-youre-doing-it-wrong/
https://jsleao.wordpress.com/2015/02/22/curry-and-compose-why-you-should-be-using-something-like-ramda-in-your-code/

There are some cases where API is the right way around, and would allow for currying or partial application:

v.sprintf('%s costs $%.2f', 'Tea', 1.5);

Here, you take config first, data last, which is the "right way". This allows you to things like:

const logMyStuff = v.sprintf.bind(null, "%s costs $%.2f")
logMyStuff("Tea", 1.5)
logMyStuff("Coffee", 2.40)

which allows you to use this function in compose chains, for example.

You cannot do that with this function:

v.replaceAll('good morning', 'o', '*');

If the order were reversed, and currying implemented, you could do this:

const changeOsToStars = v.replaceAll("o", "*")

And now you have a function you can use over and over.

With the use of FP (and in particular partial application and currying) on the rise in JavaScript, I think this library should take a leaf from ramda's book and put config first, data last, and curry by default.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions