https://github.com/rjmk/fantasy-derivations
Use methods on ADTs whether or not they're defined
https://github.com/rjmk/fantasy-derivations
Last synced: 13 days ago
JSON representation
Use methods on ADTs whether or not they're defined
- Host: GitHub
- URL: https://github.com/rjmk/fantasy-derivations
- Owner: rjmk
- Created: 2016-04-25T22:44:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-25T22:49:20.000Z (almost 10 years ago)
- Last Synced: 2025-09-06T09:56:39.124Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-functional-programming - **fantasy-derivations** - Use methods on ADTs whether or not they're defined
- awesome-functional-programming - **fantasy-derivations** - Use methods on ADTs whether or not they're defined
README
# fantasy-derivations
The [fantasy-land][fantasy-land] spec only requires ADTs to define the minimum
set of methods necessary for its type. Others can be derived. Fantasyland
gives the code necessary for the derivations, but leaves it up to either the
implementer or consumer to put them to use. `fantasy-derivations` allows you to
access methods on various ADTs that can support them without worrying whether
they are in fact defined.
[fantasy-land]: https://github.com/fantasyland/fantasy-land
## Example
```js
var fallback = require('fantasy-derivations')
var monad = require('some-monad-library-with-only-chain-defined')
var my_monad = monad.of(0)
fallback('map', my_monad)(function (n) { return n + 1 })
// monad.of(1)
```
## API
The exported function takes a string (a method name) and an ADT and does its
best to return a function for that ADT matching spec.