JSPM

u3

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

u3 - Utility Functions

Package Exports

  • u3

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

Readme

u3 - Utility Functions

This lib contains utility functions for e3, dataflower and other projects.

Documentation

Installation

npm install u3
bower install u3

Usage

In this documentation I used the lib as follows:

var u3 = require("u3"),
    cache = u3.cache,
    eachCombination = u3.eachCombination;

Function wrappers

cache

The cache(fn) function caches the fn results, so by the next calls it will return the result of the first call. You can use different arguments, but they won't affect the return value.

var a = cache(function fn(x, y, z){
    return x + y + z;
});
console.log(a(1, 2, 3)); // 6
console.log(a()); // 6
console.log(a()); // 6

It is possible to cache a value too.

var a = cache(1 + 2 + 3);
console.log(a()); // 6
console.log(a()); // 6
console.log(a()); // 6

Math

eachCombination

The eachCombination(alternativesByDimension, callback) calls the callback(a,b,c,...) on each combination of the alternatives[a[],b[],c[],...].

eachCombination([
      [1, 2, 3],
      ["a", "b"]
  ], console.log);
  /*
      1, "a"
      1, "b"
      
      2, "a"
      2, "b"
      
      3, "a"
      3, "b"
  */

You can use any dimension and number of alternatives. In the current example we used 2 dimensions. By the first dimension we used 3 alternatives: [1, 2, 3] and by the second dimension we used 2 alternatives: ["a", "b"].

License

MIT - 2016 Jánszky László Lajos