Nattily Polished Marbles
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

lambda-jam

0.0.3 • Public • Published

lambda-jam

lambda-jam is a sweet.js macro, λ, which is used to create shorthand, anonymous functions with special argument identifiers. Its functionality is inspired by clojure's shorthand function macro, #().

npm install lambda-jam

Examples

lambda-jam's real power is derived from its special argument identifiers and the fact that it returns the last expression for you. _1 references the first argument, _2 references the second argument and so on up until _9. Though, the hope is that you're not passing 9 arguments to a function.

var square = λ(_1 * _1);
console.log(square(4)); // 16
 
var sum = [1, 2, 3].reduce( λ(_1 + _2) );
console.log(sum); // 6
 
var tweets = [
  {viewed: true, msg: "kjadf"},
  {viewed: false, msg: "sweet"},
  {viewed: false, msg: "js"}
];
 
var joinedMsg = tweets.filter( λ(!_1.viewed && _1.msg) ).map( λ(_1.msg) ).join('.');
console.log(joinedMsg); // sweet.js

Check the test suite for a few more examples.

Tests

make test

License

MIT

Keywords

none

install

npm i lambda-jam

Downloadsweekly downloads

4

version

0.0.3

license

none

last publish

collaborators

  • avatar
Report a vulnerability