6 ms·
I believe you showed in one of your demonstrations (or someone else showing ramda), a very simple elegant example: > sum = reduce(add, 0) > sum([1,10,2
by tolmasky 11y ago
I believe you showed in one of your demonstrations (or someone else showing ramda), a very simple elegant example:
> sum = reduce(add, 0)
> sum([1,10,20])
With something like trine, composition can only happen really happen at usage-time, while with Ramda it allows you to reason about the operations separate from the data. I suppose trine could achieve the same by further complicating with some sort of dummy data:
sum = __placeholder__.reduce(add, 0);
[1,10,20].::sum()
But this gets difficult because __placeholder__.reduce itself needs to return something that can be chained (certainly doable to return a function that is also a dummy object I suppose?). But anyways, to me this starts looking more and more complex, and making it harder to reason about constructing (composing) NEW functions from existing ones.
- CrossEye 11y agoThat is ceratainly one of my standard examples. The best answer to this seems to be simply: var sum = ls => ls.reduce(add, 0) ISTM that this is neither as elegant nor as easy to reason about, but it's also not horrible. It really moves away from the easy association that Ramda makes between var currentTotal = reduce(add, 0, nbrs); and var sum = reduce(add, 0); //=> :: [Number] -> Number Of course this arrow syntax is ES6 (or transpiler) only, but the library is predicated on that notion. Ramda is a bit of an oddity, still maintaining compatibility with ES3 - ES6.
- quinnirill 11y agoTrine can actually already do this particular example: sum = reduce::partial(add, 0); [1,10,20]::sum();