Last active
November 24, 2016 07:12
-
-
Save rbuckton/075a165ac3379b7d848cd908ad92bdb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// operators proposal | |
// partial application (? and ...) | |
f(?, 1) // (_a = f, _b = 1, (_c) => _a(_c, _b)) | |
f(?, 1, ?) // (_a = f, _b = 1, (_c, _d) => _a(_c, _b, _d)) | |
f(?1, ?0) // (_a = f, (_b, _c) => _a(_c, _b)) | |
f(...) // (_a = f, (..._b) => _a(..._b)) | |
f(?, 1, ...) // (_a = f, _b = 1, (_c, ..._d) => _a(_c, _b, ..._d)) | |
o.f(?, 1) // (_a = o.f, _b = 1, (_c) => _a(_c, _b)) | |
// composition (~> and ~<) | |
f ~> g // (_a = f, _b = g, (_c) => _b(_a(_c))) | |
f ~< g // (_a = f, _b = g, (_c) => _a(_b(_c))) | |
// pipeline (|>) | |
x |> f // (_a = x, f(_a)) | |
x |> f () // (_a = x, f()(_a)) | |
x |> f (?, 1) // (_a = x, f(?, 1)(_a)) | |
// (_a = x, (_b = f, _c = 1, (_d) = _b(_c, _d))(_a)) | |
(x, y) |> f (?, ?) // (_a = x, _b = y, f(?, ?)(_a, _b)) | |
// (_a = x, _b = y, (_c = f, (_d, _e) => _c(_d, _e))(_a, _b)) | |
(...x) |> f (...) // (_a = x, f(...)(..._a)) | |
// (_a = x, (_b = f, (..._c) => _b(..._c))(..._a)) | |
// prefix bind (::) | |
:: f // f.bind(null) | |
:: f () // f.bind(null) () | |
// f.call(null) | |
:: o.f // o.f.bind(o) | |
:: o.f () // o.f.bind(o) () | |
// o.f () | |
:: o.f (?) // (o.f.bind(o))(?) | |
// (_a = o.f.bind(o), (_b) => _a(_b)) | |
// infix bind (::) | |
x :: f // (_a = x, f.bind(_a)) | |
x :: f () // (_a = x, f.bind(_a))() | |
x :: f (1) // (_a = x, f.bind(_a))(1) | |
x :: f (?) // (_a = x, f.bind(_a))(?) | |
// (_a = (_b = x, f.bind(_b)), (_c) => _a(_c)) | |
x :: f (...) // (_a = x, f.bind(_a))(...) | |
// (_a = (_b = x, f.bind(_b)), (..._c) => _a(..._c)) | |
x :: o.f () // (_a = x, o.f.bind(_a))() | |
x :: o.f (?) // (_a = x, o.f.bind(_a))(?) | |
// (_a = (_b = x, o.f.bind(_b)), (_c) => _a(_c)) | |
// null-coalesce | |
x ?? y // ((_a = x, _a != null) ? _a : y) | |
// null-propagating property access | |
x?.y // ((_a = x, _a == null) ? _a : _a.y) | |
// null-propagating element access | |
x?.[y] // ((_a = x, _a == null) ? _a : _a[y]) | |
// null-propagating call | |
x?.() // ((_a = x, _a == null) ? _a : _a()) | |
x?.y() // ((_a = x, _a == null) ? _a : _a.y()) | |
x?.y?.() // ((_a = x, _a == null) ? _a : (_b = _a.y, _b == null) ? _b : _b.call(_a)) | |
x?.[y]?.() // ((_a = x, _a == null) ? _a : (_b = _a[y], _b == null) ? _b : _b.call(_a)) | |
// null-propagating new | |
new x?.() // ((_a = x, _a == null) ? _a : new _a()); | |
// exponentiation operator function | |
(**) // (a, b) => a ** b | |
// multiplicative operator function | |
(*) // (a, b) => a * b | |
(/) // (a, b) => a / b | |
(%) // (a, b) => a % b | |
// additive operator function | |
(+) // (a, b) => a + b | |
(-) // (a, b) => a - b | |
// shift operator function | |
(<<) // (a, b) => a << b | |
(>>) // (a, b) => a >> b | |
(>>>) // (a, b) => a >>> b | |
// relational operator function | |
(<) // (a, b) => a < b | |
(<=) // (a, b) => a <= b | |
(>) // (a, b) => a > b | |
(>=) // (a, b) => a >= b | |
(instanceof) // (a, b) => a instanceof b | |
(in) // (a, b) => a in b | |
// equality operator function | |
(==) // (a, b) => a == b | |
(===) // (a, b) => a === b | |
(!=) // (a, b) => a != b | |
(!==) // (a, b) => a !== b | |
// bitwise operator function | |
(&) // (a, b) => a & b | |
(|) // (a, b) => a | b | |
(^) // (a, b) => a ^ b | |
// logical operator function | |
(&&) // (a, b) => a && b | |
(||) // (a, b) => a || b | |
// unary additive operator function | |
(~+) // (a) => +a | |
(~-) // (a) => -a | |
// unary bitwise operator function | |
(~) // (a) => ~a | |
// unary logical operator function | |
(!) // (a) => !a | |
// other unary operator function | |
(void) // (a) => void a | |
(typeof) // (a) => typeof a | |
// samples | |
element.addEventListener("click", ::this.onClick); | |
// assumes first arg is iterable | |
[1, 2, 3] | |
|> map(?, (*)(?, 2)) // [2, 4, 6] | |
|> filter(?, (<)(?, 5)) // [2, 4] | |
|> reduce(?, (*)) // 8 | |
// assumes `this` is iterable | |
[1, 2, 3] | |
:: map((*)(?, 2)) // [2, 4, 6] | |
:: filter((<)(?, 5)) // [2, 4] | |
:: reduce((*)) // 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment