Last active
August 29, 2015 14:24
-
-
Save benadamstyles/c3474da1f8601c9d2db2 to your computer and use it in GitHub Desktop.
Sweet.js macros
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
// for rebuilding an array without reassignment | |
macro rebuild { | |
rule {$oldArr $newArr} => { | |
$oldArr.length = 0 | |
$oldArr.push.apply($oldArr, $newArr) | |
} | |
} | |
rebuild arr newArr; | |
// sugar for underscore's _.chain() method | |
let chain = macro { | |
rule {$obj $($method) ... ~} => { | |
_.chain($obj).$method ... .value() | |
} | |
} | |
chain {a: 1, b: 2} groupBy(() => {}).pick(() => {})~; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment