40 karma · joined May 13, 2012
haha man i dont know how many time ive written a reverse/flip function in our codebase and then erased it an hour later cause i know i would be called out on it lol
var nums = Array.apply(0, Array(300)).map(function(x, idx) {
return idx;
});
var filter = ramda.filter;
var map = ramda.map;
var reduce = ramda.reduce;
var compose = ramda.compose;
var gt100pred = function(x) {
return x > 100;
};
var add = function(a, b) {
return a + b;
};
var result = nums
.filter(gt100pred)
.map(Math.sqrt)
.reduce(add, 0);
var gt100 = filter(gt100pred);
var sqrt = map(Math.sqrt);
var accum = reduce(add, 0);
var result = compose(accum, sqrt, gt100)(nums);
=============with the above your code does look shorter. but there is one big plus with the latter that not only can you pass around the predicate but the operation in itself can be passed around(gt100 is reusable etc..). (ramda actually works like a functional library wherein the function/predicate is the first argument and the data structure is the last. this makes partial function application and currying work much better)
also when we do away with the boilerplate the final thing looks like this:
// "I want the sum of the square roots
// of all numbers greater than 100 in this list".
var result = nums
.filter(gt100pred)
.map(Math.sqrt)
.reduce(add, 0);
vs // think of it as pipelining from right to left.
// get any number > 100, sqrt it, then accumulate it.
var result = compose(accum, sqrt, gt100)(nums);
and if this was haskell: foldl (+) 0 . map sqrt . filter (> 100) $ [0..300]this application also has to have a pluggable(200+ different company business/validation rules) rule engine, and being able to configure angularjs services through its providers interface has been very helpful with that problem.
we're not done yet so i can't give a final verdict but we've been overall pleased with the framework so far. i also agree with some of the sentiments in here where angularjs does not currently seem to have a culture of what is "idiomatic" angular which can be very detrimental in the short and long run.
one of the reasons we didn't go with ember is that the decision was made at the time where in they were making huge changes to ember.
class SomeClass implements Linq {}
public interface Linq {
public IEnumerable where(Func) { default implementation... }
public IEnumerable orderBy(Func) { default implementation... }
}