Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syarul/monads-maybe
A simple wrapper of javascript statement branching that provide safe error handling and test friendly
https://github.com/syarul/monads-maybe
Last synced: 3 days ago
JSON representation
A simple wrapper of javascript statement branching that provide safe error handling and test friendly
- Host: GitHub
- URL: https://github.com/syarul/monads-maybe
- Owner: syarul
- License: mit
- Created: 2017-09-24T07:12:45.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-24T10:09:40.000Z (about 7 years ago)
- Last Synced: 2024-09-23T15:18:04.877Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: READMe.md
- License: LICENSE
Awesome Lists containing this project
README
# monads-maybe
A simple wrapper of javascript statement branching that provide safe error handling and test friendly
## Usage
```npm install monads-maybe```
```javascript
import mayBe from 'monads-maybe'
const arr = ['one', 'two', 'three']
const log = console.log.bind(console)
const hasOne = arr.indexOf('one')
let isOne = mayBe.is(~hasOne, 'has one')
log(isOne) // has one
isOne = mayBe.not(~hasOne, 'has one')
log(isOne) // false
const hasFour = arr.indexOf('four')
let isFour = mayBe.not(~hasFour, 'has no four')
log(isFour) // has no four
isFour = mayBe.is(~hasFour, isFour = 'hello', isFour = 'world')
log(isFour) // world
isFour = mayBe.so(~hasFour, true, false)
log(isFour) // false
```## License
The MIT License (MIT)
Copyright (c) 2017 Shahrul Nizam Selamat