flyd icon indicating copy to clipboard operation
flyd copied to clipboard

Use fj-curry instead of Ramda curry.

Open RangerMauve opened this issue 10 years ago • 9 comments

Ramda's curry seems to have a bit more code to it compared to fj-curry which is more minimal and has the same features.

RangerMauve avatar Sep 03 '15 19:09 RangerMauve

:+1:

avesus avatar Sep 03 '15 20:09 avesus

The biggest difference in code size seems to be that fj-curry does not return functions with the correct length. So curry((a, b, c) => foo).length === 0. But it should be 3. It does not seem nice but I am not sure if it really matters.

paldepind avatar Sep 05 '15 19:09 paldepind

That's true. Does flyd rely on a proper length property anywhere? I mostly like that one wouldn't have to have all of Ramda installed just for the one curry function. It'd be nice if they split things up into separate modules in the future. :/

RangerMauve avatar Sep 08 '15 14:09 RangerMauve

Would a PR for this be welcome?

RangerMauve avatar Sep 08 '15 14:09 RangerMauve

@RangerMauve, other modules can rely on this.

StreetStrider avatar Sep 08 '15 17:09 StreetStrider

@RangerMauve http://rollup.js/ could be a way to selectively import only R.curry

kwijibo avatar Oct 28 '15 15:10 kwijibo

@kwijibo Thanks for the link, however flyd already just imports curry. I just like it when only the code needed is installed at all.

RangerMauve avatar Oct 28 '15 15:10 RangerMauve

@RangerMauve

| Does flyd rely on a proper length property anywhere?

Some Ramda functions depend on the length property. So the approach may cause an issue if in a mixed flyd/ramda setting, some fj-curried function gets eventually passed to some ramda function that relies on it. So in general it's good to preserve it.

monfera avatar Dec 28 '15 17:12 monfera

The following pattern allows to curry functions that you define yourself:

function innerCurry(args, f, context) {
    return f.bind.apply(f, [context || this].concat([].slice.call(args)))
                           //there may be a more efficient way to build that array
}

function add(a,b,c) {
    // that line is a bit unusual, but it offers maximal gzippability if the cyrrification pattern
    // is repeated in many functions.
    if (3 > arguments.length) return innerCurry(arguments, add)
    return a + b + c
}

It as light as can be, and the length is preserved, so that add(1).length === 2.

The main drawback is that you can't implement curryN on top of it, and you provide ramda's version publicly ATM...

You could provide a short curryN that preserves the length on top of the new Function () constructor, but it will not work in restricted environment, and may be slow.

Edit: I accidentaly the last sentence.

pygy avatar Jan 10 '16 21:01 pygy