The Philosophy of Ramda
fr.umio.us2 pointsby CrossEye1 comments
> var isboxed = (function() {"use strict"; return function isboxed() {return this instanceof Number;}}());
> isboxed.call(5);
false 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. // process1 :: (Item -> Bool) -> [Item] -> [OtherType]
// process2 :: [Item] -> [OtherType]
process1(isOk, items); //=> [otherType1, otherType2, ...]
process2(items); //=> [otherType1, otherType2, ...]
var processR1 = seq(filter, map(toOtherType), flatten);
var processR2 = processR1(isOk);
var processT1 = (isOk, items) => items.filter(isOk).map(toOtherType).flatten()
var processT2 = items => processT1(isOk, items)
That's why I'm wondering if there's some easier way to do this. items
.filter(isOk)
.map(toOtherType)
.flatten()
But what I really want to do is build a reusable function: var process = seq(filter(isOk), map(toOtherType), flatten);
So I can at my leisure call process(items);
Or later put `process` in another sequence, or do something like: map(process, groupsOfItems)
And I don't see that Trine helps with that. Am I missing the way to use Trine to build functions, or do I simply have to wrap up a Trine construct in a function that takes a parameter, does its Trine magic, and returns that result?