Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rolangom/rolads
Monads implementation by @rolangom
https://github.com/rolangom/rolads
functional functional-js functional-programming javascript javascript-library node-js
Last synced: 7 days ago
JSON representation
Monads implementation by @rolangom
- Host: GitHub
- URL: https://github.com/rolangom/rolads
- Owner: rolangom
- License: mit
- Created: 2018-03-29T00:21:39.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-30T15:19:36.000Z (almost 7 years ago)
- Last Synced: 2024-11-11T18:11:59.981Z (2 months ago)
- Topics: functional, functional-js, functional-programming, javascript, javascript-library, node-js
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rolads
Monads implementation by @rolangom: Option (Some and None) and Either (Left and Right).```javascript
const { Left, match, None, Right, Some, Either } = require('./index');const eitherL1 = Left.of('Error');
const eitherR1 = Right.of('Success');console.log('results1 of Left should be "Error".');
const results1 = match({ left: value => value, right: value => value }, eitherL1);
console.assert(results1 === 'Error', 'Result of Left should be "Error".');console.log('results2 should be "Success".');
const results2 = match({ left: value => value, right: value => value }, eitherR1);
console.assert(results2 === 'Success', 'Result of Right should be "Success".');const optionS1 = Some.of(1);
const optionN1 = None;console.log('Result of Some should be 1.');
const result3 = match({ some: val => val, none: () => 0 }, optionS1);
console.assert(result3 === 1, 'Result of Some should be 1.');console.log('result5 should be 0.');
const result4 = match({ some: val => val, none: () => 0 }, optionN1);
console.assert(result4 === 0, 'Result of None should be 0.');```
Inspired on 'https://drboolean.gitbooks.io/mostly-adequate-guide-old/content/', https://github.com/origamitower/folktale and others.