conds

0.0.1 • Public • Published

cond

Lisp inspired conditional construct (COND) in Javascript.

COND is a function which takes an arbitrary number clauses. Each clause contains a list of two expressions. First expression is a condition (or predicate) and the second is the result. Each clause is ran in order, immediately returning the result where the condition is truthy.

Install

npm install conds
bower install conds

Usage

const cond = require('conds');
 
const fn = cond([
  [t => t === 0, `Water freezes at 0°C`],
  [t => t === 100, `Water boils at 100°C`],
  [true, t => `Nothing special happens at ${t}°C`]
]);
 
console.log(fn(0)); // 'Water freezes at 0°C'
console.log(fn(50)); // 'Nothing special happens at 50°C'
console.log(fn(100)); // 'Water boils at 100°C'

Test

npm test

License

MIT

Package Sidebar

Install

npm i conds

Weekly Downloads

39

Version

0.0.1

License

MIT

Last publish

Collaborators

  • miguelmota