https://github.com/codefeathers/fuse
FunctionSelect: Select a function that passes a condition. A functional alternative to switch-case.
https://github.com/codefeathers/fuse
flow-control function functional javascript select switch-case
Last synced: 7 months ago
JSON representation
FunctionSelect: Select a function that passes a condition. A functional alternative to switch-case.
- Host: GitHub
- URL: https://github.com/codefeathers/fuse
- Owner: codefeathers
- License: mit
- Created: 2018-04-06T11:40:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-19T05:13:10.000Z (over 7 years ago)
- Last Synced: 2025-06-19T22:53:05.177Z (8 months ago)
- Topics: flow-control, function, functional, javascript, select, switch-case
- Language: JavaScript
- Homepage:
- Size: 410 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fuse
**FunctionSelect**
`Fuse` selects a function that passes a condition.
## Usage
### Fuse
```JavaScript
const Fuse = require('@codefeathers/fuse');
const a = 100;
const result = new Fuse(a)
.on(x => x>10,
a => `${a} is greater than 10.`)
.on(x => x<10,
a => `${a} is lesser than 10.`)
.on(x => x===10,
a => `${a} is 10.`)
console.log(result.resolve()); // -> "100 is greater than 10."
```
### FuseIterable
```JavaScript
const { FuseIterable } = require('@codefeathers/fuse');
const temperatures = [ 0, 20, 30 ];
const result = new FuseIterable(temperatures)
.on(temp => temp<10,
() => `Too cold!`)
.on(temp => temp>=10 && temp <25,
() => `Just right.`)
.on(temp => temp>=25,
() => `Too warm!`)
console.log(result.resolve()); // -> [ "Too cold!", "Just right.", "Too warm!" ]
```
## Docs
Docs exist in `/docs` directory. Will be served soon.
## Development
> If you find any mistakes in code/documentation, or if you feel something could be done better, do PR :) I appreciate it.
- Always write test spec for any code you add. Make sure they run as intended.
- Add/update JSDoc comments as needed.
- Use npm scripts for linting, tests, debugging, building docs.
Place your test file as `testscript.js` in root.
The following npm scripts are available: `npm run lint`, `npm test`, `npm run debug`, `npm run docs`.
## Credits
[@Floofies](https://github.com/Floofies) was of huge help during development of this module.
Also, [@TRGWII](https://github.com/trgwii) was a source of inspiration and guidance.