Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I feel like more than anything, this example demonstrates the value of lightweight lambdas.

    var totals = splat(get('total'))(orders);
is definitely nicer than

    var totals = orders.map(function(o){return o.total;});

But there really is not much difference between the coffeescript versions (actually, I'd argue the 'map' version is much clearer in intent):

    totals = splat(get('total'))(orders);

    totals = orders.map (o)->o.total


I find

    var totals = orders.map(function(o){return o.total;});
far easier to understand than

    var totals = splat(get('total'))(orders);
And, I would had written

    var totals = orders.map(function(o){ 
        return o.total 
    })
(note the lack of semicolons and indentation)

cheers!


I was deliberately avoiding the map method to keep everything functional.


How is map not functional?

Do you mean you wanted to emphasize HOFs?


Yes. The map method is not functional in the sense that the map function is functional. In actual code, I'd use the method too.


I don't really see the method as being any less functional than the function version (ie, they're both without side effects, the method version just has 'this' as an implicit parameter).

Though I guess that's just a difference in perspective.

Edit: Having stumbled upon something else you wrote[1](Viz. "WHy the crazy idea of using a splatter instead of a mapping method or function?"), I now understand the reason you're making the distinction. Though (speaking as someone who certainly doesn't have the level of expertise to be making this semantic argument) I really don't think it's the distinction between "functional" and "not functional" so much as... "composability"?

[1] https://github.com/raganwald/homoiconic/blob/master/2013/01/...


I think a lot of people would argue that composability is what "functional" code is really interested and many of the other things that are normally associated with it are actually side-effects of the emphasis on composition.


Exactly. There's no point being "functional" for the sake of functions. It's for the benefits this style brings, an important one being composability.


LiveScript allows partially applied operators, including property access. You can do:

    totals = map (.total), orders
http://livescript.net/


> I feel like more than anything, this example demonstrates the value of lightweight lambdas.

Meh.

    totals = map (! "total") orders


There is a JS library that implements `orders.map('total')`, can't remember it's name.


The allong.es library quoted actually allows:

    splat('.total')
But you didn't hear it from me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: