Introducing Sugarless - A Functional & Context Oriented way to write JavaScript
laktek.com
laktek.com
var output = Sugarless(input)(
sanitize
, trim
, truncate, "", 200
);
is more readable than var output = truncate(trim(sanitize(input)), 200)
than you may be interested in Sugarless. Call me old school, but I prefer the latter.Also, if I can't tell the difference between a comma and a period on your _improved language syntax_ homepage, then you're doing something wrong.
fn = compose(truncate.flip().curry(20), trim, sanitize);
output = fn(input);
Better or worse?If input processing is complicated enough to have annoying syntax, it gets its own special-purpose class (if not a separate module) written in the language of the domain. Frankly there's probably several things that look like Sugarless in the codebase already. But I consider this a Good Thing:
If I want to change the way operations distribute over an Input object, I can do it in an arbitrary, appropriate way. If I'm using someone else's convenience library, I'm limited to what the library author decided I should be able to do. This happens surprisingly often in my use case and more often than not it means going back to throw away the library in question, and reimplementing what I needed in the first place.
This isn't actually a comment on Sugarless itself -- I haven't gone out and used it. But I'm quite jaded by all of the times I've had to deep dive into other people's 'convenient' JS library when it was subtly broken (or wasn't working as I'd like) to the point that I try to avoid them as best as I can.
var stooges = [{name : 'curly', age : 25},
{name : 'moe', age : 21},
{name : 'larry', age : 23}];
var youngest = _(stooges).chain()
.sortBy(function(stooge){ return stooge.age; })
.map(function(stooge){
return stooge.name + ' is ' + stooge.age; })
.first()
.value();Seems like a pretty glaring oversight to me.
Seems this example explain how deal with functions as arguments in the Sugarless chain. https://github.com/laktek/SugarlessJS/blob/master/examples/c...