JSPM

lambdax

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

`lambdax` is an small module that allows you to implement partial application and build lambda expressions.

Package Exports

  • lambdax

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 (lambdax) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lambdax

lambdax is an small module that allows you to implement partial application and build lambda expressions.

Install

  • npm
npm install --save lambdax
  • bower
bower install --save lambdax

Usage

lambdax exposes two functions: partial() and negate();

var partial = require('../lambdax').partial;
var negate = require('../lambdax').negate;

partial()

  • partial() simple use:
function sum(a, b, c) {
  return a + b + c;
}
var sumPlus15 = partial(sum, 15);
sumPlus15(25, 20); // => 60
  • partial() simple use passing context and arguments:
function getColeguesNamesFromPeople(people) {
  var _self = this;
  return people.reduce(function (colegues, person) {
    if (person.occupation === _self.occupation) {
      colegues.push(person.firstName);
    }

    return colegues;
  }, []);
}

var getJohnColeguesNamesFromPeople = partial(
  john, // context
  getJohnColeguesNamesFromPeople,
);

getJohnColeguesNamesFromPeople(people);
  • partial() use as a builder:
var findBackendDeveloper = partial()
  .expression(function () {
    return this.reduce(function (backendDevelopers, person) {
      if (person.occupation === 'Backend Developer') {
        backendDevelopers.push(person);
      }

      return backendDevelopers;
    }, []);
  })
  .context(people)
  .build();

findBackendDeveloper();

negate()

  • negate() simple use
var f = negate(function () { return true });
f() // => false.
  • negate() simple use passing context and arguments:
var minAge = 18;
var maxAge = 30;
var isAgeNotInRange = negate(
  john, // context
  function (minAge, maxAge) {
    return this.age >= minAge && this.age <= maxAge;
  },
  minAge
  // we could've passed maxAge too,
  // but we didn't just to demonstrate that can pass it latter
);

isAgeNotInRange(maxAge);
  • negate() use as a builder:
var isNotAgeInRange = negate()
  .expression(function (minAge, maxAge) {
    return this.age >= minAge && this.age <= maxAge;
  })
  .context(john)
  .argument(18)
  .argument(30)
  .build();

isNotAgeInRange();

Note: see test folder for more examples.