Name Last Update
..
.github/workflows Loading commit data...
.editorconfig Loading commit data...
.eslintrc.json Loading commit data...
.gitattributes Loading commit data...
README-template.md Loading commit data...
README.md Loading commit data...
build.js Loading commit data...
index.d.ts Loading commit data...
index.js Loading commit data...
index.test.js Loading commit data...
package.json Loading commit data...

fp-and-or

npm version

Simple and and or functional programming predicates.

  • and(...fs): (...args): boolean - Returns a predicate that returns true if all arguments are true or evaluate to true for the given input.
  • or(...fs): (...args): boolean - Returns a predicate that returns true if at least one argument is true or evaluates to true for the given input.

A predicate is a function that returns a boolean, commonly used in Array.prototype.filter.

e.g.

const isEven = n => n%2 === 0
const isPositive = n => n > 0

// un-fancy
items.filter(x => isEven(x) || isPositive(x))

// fancy
items.filter(or(isEven, isPositive))

Install

npm install --save fp-and-or

Usage

const { and, or } = require('fp-and-or')

<%=usage%>