Comparing version 0.0.0 to 0.0.1
{ | ||
"name": "akh.either", | ||
"version": "0.0.0", | ||
"description": "Akh either monad", | ||
"version": "0.0.1", | ||
"description": "Akh either monad and monad transformer", | ||
"author": "Matt Bierner", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -1,8 +0,20 @@ | ||
Either monad transformer for [Akh Javascript Monad library](https://github.com/mattbierner/akh) | ||
# Either Monad and Monad Transformer for [Akh Javascript Monad Library](https://github.com/mattbierner/akh) | ||
The EitherT transformer, `EitherT`, adds either values to a monad. The base type, `Either`, provides either computation logic on its own. | ||
The `EitherT` and `Either` is a monad, functor, and applicative functor. | ||
```bash | ||
# To use as standalone package | ||
$ npm install --save akh.cont | ||
# To use as part of akh library | ||
$ npm install --save akh | ||
``` | ||
## Usage | ||
The `EitherT` and `Either` implement the [Fantasy Land][fl] monad, functor, and applicative functor interfaces. | ||
<a href="https://github.com/fantasyland/fantasy-land"> | ||
<img src="https://raw.github.com/fantasyland/fantasy-land/master/logo.png" align="right" width="82px" height="82px" alt="Fantasy Land logo" /> | ||
</a> | ||
```js | ||
@@ -18,5 +30,3 @@ // Either monad | ||
## Running | ||
#### `Either::run(m)` | ||
#### `Either.run(m)`, `m.run()` | ||
Perform a continuation computation `m` and get the result as an `Either`. `Either` has a `value` property plus either a `left` or `right` property to show its type | ||
@@ -31,7 +41,7 @@ | ||
#### `EitherT::run(m)` | ||
#### `EitherT.run(t)`, `t.run()` | ||
Same as `Either.run` but for a monad transformer. Returns an `Either` value inside of the inner monad. | ||
#### `Either::either(m, leftCallback, rightCallback)` | ||
#### `Either.either(m, leftCallback, rightCallback)`, `m.either(l, r)` | ||
Perform a continuation computation `m` and invoke `leftCallback` for `left` results and `rightCallback` for `right` results. | ||
@@ -48,4 +58,4 @@ | ||
#### `EitherT::either(m, leftCallback, rightCallback)` | ||
Same as `Either::either` but for transformed types | ||
#### `EitherT.either(t, leftCallback, rightCallback)`, `t.either(l, r)` | ||
Same as `Either.either` but for transformed types | ||
@@ -68,6 +78,22 @@ | ||
```js | ||
const c = Either.left(3) | ||
const c = | ||
Either.left(3) | ||
.map((x) => -x); | ||
Either.either(c, console.error, console.log); // errors: 3 | ||
Either.either(c, console.error, console.log) // errors: 3 | ||
``` | ||
## Contributing | ||
Contributions are welcome. | ||
To get started: | ||
```bash | ||
$ cd akh-either | ||
$ npm install # install dev packages | ||
$ npm test # run tests | ||
``` | ||
[fl]: https://github.com/fantasyland/fantasy-land |
@@ -13,8 +13,16 @@ "use strict" | ||
assert.deepEqual( | ||
Either.either(c, l, r), | ||
[true, 3]) | ||
[true, 3], | ||
Either.either(c, l, r)) | ||
assert.deepEqual( | ||
Either.run(c), | ||
{ right: true, value: 3 }) | ||
[true, 3], | ||
c.either(l, r)) | ||
assert.deepEqual( | ||
{ right: true, value: 3 }, | ||
Either.run(c)) | ||
assert.deepEqual( | ||
{ right: true, value: 3 }, | ||
c.run()) | ||
}) | ||
@@ -21,0 +29,0 @@ |
@@ -58,3 +58,11 @@ /** | ||
}) | ||
Instance.prototype.run = function() { | ||
return EitherT.run(this) | ||
} | ||
Instance.prototype.either = function(l, r) { | ||
return EitherT.either(this, l, r) | ||
} | ||
return Instance | ||
@@ -82,2 +90,2 @@ } | ||
module.exports = EitherT | ||
module.exports = EitherT |
@@ -29,2 +29,10 @@ "use strict" | ||
module.exports = Either | ||
Either.prototype.run = function() { | ||
return Either.run(this) | ||
} | ||
Either.prototype.either = function(l, r) { | ||
return Either.either(this, l, r) | ||
} | ||
module.exports = Either |
12099
274
96