An open API service indexing awesome lists of open source software.

https://github.com/itsabdelrahman/functional-conditional

🐏 Conditional Logic: The Functional Way
https://github.com/itsabdelrahman/functional-conditional

case else if switch then when

Last synced: 22 days ago
JSON representation

🐏 Conditional Logic: The Functional Way

Awesome Lists containing this project

README

        


functional-conditional

Conditional Logic: The Functional Way

## Usage

Turn this:

```ts
let result = null;

switch (someValue) {
case 0:
result = 'zero';
break;
case 1:
result = 'one';
break;
case 2:
result = 'two';
break;
}
```

Into this:

```ts
import conditional from 'functional-conditional';

const result = conditional([
{ if: 0, then: 'zero' },
{ if: 1, then: 'one' },
{ if: 2, then: 'two' },
])(someValue);
```

## License

MIT