https://github.com/zkat/fl-protocols
fantasy-land specification bridge for @zkat/protocols
https://github.com/zkat/fl-protocols
Last synced: 8 months ago
JSON representation
fantasy-land specification bridge for @zkat/protocols
- Host: GitHub
- URL: https://github.com/zkat/fl-protocols
- Owner: zkat
- Created: 2016-09-06T06:41:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-12T09:41:28.000Z (over 9 years ago)
- Last Synced: 2025-05-12T15:23:10.528Z (8 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fantasyland Protocols
This module provides a
[`fantasy-land`](npm.im/fantasy-land) compatibility
layer using [`protoduck`](npm.im/protoduck). The compatibility
layer includes protocol definitions for all protocols with methods listed in the
`fantasy-land` spec, and includes automatic two-way compatibility between
methods defined in either world.
That is: you can use protocol functions exported by `protoduck-fl` on any
object(s) that have `fantasy-land` methods implemented, without any extra work,
and and methods you define using `protoduck-fl` will automatically become
available to `fantasy-land` users even if they are not directly using
`protoduck-fl`.
Even multiple-dispatched protocols will work two-ways, so `protoduck-fl` is a
great way to augment your `fantasy-land` implementations!
## Example
```
// Basic two-way compatibility
> var Monoid = require('protoduck-fl/monoid')
> var fl = require('fantasy-land')
> Monoid(Number, { empty: () => 0 })
> (1)[fl.empty]()
0
> var obj = { [fl.empty]: () => ({}) }
[object Object]
> Monoid.empty(obj)
{}
// Multiple dispatch on fl methods
> var Setoid = require('protoduck-fl/setoid')
> Setoid(Number, [Number], {
equals: (n) => +this === n
})
> Setoid(Number, [String], {
equals: (s) => +this === parseFloat(s)
})
> Setoid(String, [Number], {
equals: (n) => parseFloat(''+this) === n
})
> (10)[fl.equals]("10")
> (5)[fl.equals]("5")
true
> ("1")[fl.equals](1)
true
> Setoid.equals("1", 1)
true
```