1.1.3 • Published 8 years ago

functional-switch v1.1.3

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Functional Switch

A functional implementation of switch.

This library is in alpha now. It would be great if you help me try it.

Installation

npm install functional-switch --save

Usage

import { cond, when, otherwise } from 'functional-switch'

// simple example
const isFruitOrVegetable = cond(
  when('apple', 'isFruit'),
  when('orange', 'isFruit'),
  when('eggplant', () => {
    return 'isVegetable'
  }),
  otherwise('isFruit')
)

isFruitOrVegetable('apple') // isFruit

API

when()

when(
  clause: any,
  statement: any
): [clause, statement]

otherwise()

otherwise(
  statement: any
): [statement]

cond()

cond(
  ...conditions: [clause, statement] | [statement]
): (expression: any) => any
1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago