metascript/metascript — pull request #57 by drslump (2014-11-28 22:14:05+00:00)
Title: Proof of concept for a flexible lambda operator

Many JavaScript libraries nowadays require passing function expressions for almost everything, when switching from using `function` to an *arrow syntax* the readability improves but after a while they don't solve completely the visual stress produced by excessive punctuation in the code.

One of the things that I really like about Boo is its *colon operator*, when used after a callable it introduces a *block* (aka function expression) that gets passed as last argument to the LHS callable.

```boo
$('.foo').on('click'):
console.log "Hi! I'm a .foo element!"
```
```js
$('.foo').on('click', function () { console.log("Hi, I'm a .foo element!"); });
```

The current way to do something like that on *metascript* is by using the `#->` function operator:

```js
($ '.foo').on
'click'
#-> console.log '...'
```

It's not bad but I missed Boo's colon form. After a while messing with overloading the colon on *metascript* to serve this purpose I finally gave up and decided to try a different approach. It not only helps on the previous scenarios but basically serves as a very *light weight syntax* to wrap any expression in a function so it can passed around at runtime.

> **Note**: Right now it uses `\\` as operator, I think though that `\` looks even better but it'll require some changes in the parser. The examples here use the `\` syntax :)

```js
$('.foo').on 'click' \
console.log '...'
```

That's quite nice but what I found is that it solves other patterns too, for instance when working with *functional* libraries like *lo-dash*:

```js
var result = _(my-array) |:
filter \ <= 300 ; auto completes placeholder with #it
map _.memoize \ #it * 2
take 10
```

The beauty of it is that the ceremony needed to define some expression as a lambda is reduced to a simple character, however it's a character that really stands out when reading the code, even without syntax highlighting. As such it plays very well with a large portion of todays javascript requiring the use of logic wrapped into functions for some variant of deferred execution and flow control.