@plexis/when

0.0.22 • Public • Published

when

when is used for checking and chaining within the composition for supercharged functions.

npm i @plexis/when

Usage

import compose from '@plexis/compose';
import when from '@plexis/when';

const inc = x => x + 1;
const add = (x, y) => x + y;
const setToZero = () => 0;

const compose = (...fns) => x => fns.reduce((r, f) => f(r), x);
const when = (cond, f) => x => (cond(x) ? f(x) : x);

const ops = compose(
  inc,
  x => add(x, 2),
  when(num => num > 0, compose(setToZero))
);

ops(1); // returns 0
ops(100); // returns 0
ops(-100); // returns -97

Aliases

import when from '@plexis/when';
import {when} from 'plexis';

Package Sidebar

Install

npm i @plexis/when

Weekly Downloads

9

Version

0.0.22

License

MIT

Unpacked Size

4.11 kB

Total Files

6

Last publish

Collaborators

  • vorillaz