Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

miguelmota/cond

Repository files navigation

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

About

Lisp inspired conditional construct (COND) in Javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published