Skip to content

Instantly share code, notes, and snippets.

@benadamstyles
Last active August 29, 2015 14:24
Show Gist options
  • Save benadamstyles/c3474da1f8601c9d2db2 to your computer and use it in GitHub Desktop.
Save benadamstyles/c3474da1f8601c9d2db2 to your computer and use it in GitHub Desktop.
Sweet.js macros
// 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