Echo JS 0.11.0

<~>
gcanti 3695 days ago. link 4 points
When I see concepts like transducers I'm always torn in two:

**my theoretical side** is excited: reducing (pun intended) a bunch of different operations to a minimal set of basic, composable operations is an awesome intellectual challenge. 
I imagine how succinct, reusable and multipurpose could become my code.

**my pragmatic side** is skeptic: in functional programming it's a little step to end up with incomprehensible code, for me and my coworkers:

    var inc = function(n) { return n + 1; };
    var isEven = function(n) { return n % 2 == 0; };
    var xf = comp(map(inc), filter(isEven));
    console.log(into([], xf, [0,1,2,3,4])); // [2,4]

vs

    var inc = function(n) { return n + 1; };
    var isEven = function(n) { return n % 2 == 0; };
    [0,1,2,3,4].map(inc).filter(isEven); // [2,4]

The latter is comprehensible by everyone (and no additional library). 
Ok you iterate twice but if you really (REALLY) have performance problems, maybe you'd end up
with something like this:

    var input = [0,1,2,3,4];
    var output = [];
    var x;
    for (var i = 0, len = input.length ; i < len ; i++ ) {
      x = input[i] + 1; // map
      if (x % 2 == 0) ouput.push(x); // filter
    }

Replies