Skip to content

wuct/functional-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A functional implementation of switch.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published