Quick install instructions
npm install lambda-js
For browsers, just copy
./lib/lambda.min.js (generated by UglifyJS)and include it in a
npm test to check your changes (using nodeunit) haven't broken existing functionality. Literate programming documentation can be found inside of the
/docs directory, generated by docco.
Syntactic sugar for lambda one-liners without a performance penalty
Until ECMAScript 6 gives us the fat-arrow syntax for one-liners in functional style evaluation,
Such one-liners include a lot of ugly noise:
var adder = "a,b" "return a+b";
And with that capability, and caching already-constructed lambdas so there's no performance penalty beyond the initial construction, we can have nice one-liners even before ES6:
var l = ;12345678910;
Lambdas are "pure" functions, not closures, so the following won't work:
var l = ;var foo = 'bar';var impureLambda = ; // Will throw a ReferenceError, foo not defined
But pure functions are perfectly predictable because their output is totally determined by their inputs, and the closures where they are defined cannot affect their behavior, so it can also be useful to "scrub" a larger function with lambda-js:
var l = ;var scrubbedFunction =;
Lambda-js attaches a
pure property to the lambdas (with a value of
true), which can be used by other libraries to determine if the function they have been provided is a pure function or a closure.
If you need to transmit lambdas over the wire, Lambda-js provides a simple serialization and deserialization mechanism.
var l = ;var funcObj = l;var funcObjStr = JSON; // Doesn't throwvar func = l;
Copyright (C) 2012-2013 by David Ellis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.