JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 107
  • Score
    100M100P100Q73761F
  • License MIT

A Lambda String implementation for Node.js that supports some ES6

Package Exports

  • lambda-30

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lambda-30) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Lambda-30

A Lambda String implementation for Node.js that supports some ES6.

Install

npm install lambda-30

Testing

npm test

Usage

###Basic

var L = require('lambda-30').Lambda;
var f = L('(a, b)=>a+b');
var val = f(5, 8);
// val is 13
f = L('$.a+$.b'); // No params supplied used $ as self reference
val = f({a: 3, b: 5});
// val is 8

###Options

var Lambda = require('lambda-30').Lambda;
var L = new Lambda({selfSymbol: 'self'});
var f = L.compile('self.a+self.b');
var val = f({a: 3, b: 5});
// val is 8
// or you can do
var val = L.execute({a: 3, b: 5});
// val is still 8

###Multi-line

var L = require('lambda-30').Lambda;
// note: long string form used for convience only
var f = L(`(a, b)=>{
    var c = 2;
    var sum = a+b;
    var avg = sum / c;
    return {
      count: c,
      sum: sum,
      avg: avg
    };
}`);

###...rest

var L = require('lambda-30').Lambda;
// note: long string form used for convience only
var f = L(`(...nums)=>{
    var c = nums.length;
    var sum = nums.reduce(function(curr, next){
      return curr + next;
    }, 0);
    var avg = sum / c;
    return {
      count: c,
      sum: sum,
      avg: avg
    };
}`);

###toJSON

Really this should be called toString but I didn't want to override the default toString implementation.

var L = require('lambda-30').Lambda;
var expected = '(a, b)=>{return a+b}';
var e = L(expected);
var js = e.toJSON();
assert(js===expected);

var e = Lambda(function($){
    return $.a+$.b;
  });
var s = e.toJSON();
var expected = '($)=>{\n        return $.a+$.b;\n      }';
assert(s===expected);