switch-fn
Write a functional switch statement.
Install
$ npm install --save switch-fn
Usage
var Switch = var fn = var result = // => calls actionA with 'a' and gives back actionA's return value
API
Switch(cases)
-> function
cases
Required
Type: object
An object, with keys being the 'cases' to match against and values being the function to call in each case.
If no case matching the input is found and a 'default' case is given, it will be used.
More Examples
As part of a data pipeline
var pipe = var Switch = var onStatus = var result = { return userstatus}
Pass in an array for numbers only
var Switch = var fn =
Fibonacci
var fib = Switch({ 0: (n) => n, 1: (n) => n, default: (n) => fib(n - 1) + fib(n - 2)}); fib(10) // => 55
License
MIT © Andrew Joslin