Skip to content

Commit

Permalink
remove monad{Zero,Plus,Or} specs
Browse files Browse the repository at this point in the history
  • Loading branch information
safareli committed Nov 1, 2016
1 parent 05f01ac commit 00fabbb
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 157 deletions.
24 changes: 0 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ structures:
* [Chain](#chain)
* [ChainRec](#chainrec)
* [Monad](#monad)
* [MonadZero](#monadzero)
* [MonadPlus](#monadplus)
* [MonadOr](#monador)
* [Extend](#extend)
* [Comonad](#comonad)
* [Bifunctor](#bifunctor)
Expand Down Expand Up @@ -458,27 +455,6 @@ the [Applicative](#applicative) and [Chain](#chain) specifications.
1. `M.of(a).chain(f)` is equivalent to `f(a)` (left identity)
2. `m.chain(M.of)` is equivalent to `m` (right identity)

### MonadZero

A value that implements the MonadZero specification must also implement
the [Monad](#monad) and [Alternative](#alternative) specifications.

1. `M.zero().chain(f)` is equivalent to `M.zero()` (annihilation)

### MonadPlus

A value that implements the MonadPlus specification must also implement
the [MonadZero](#monadzero) specification.

1. `x.alt(y).chain(f)` is equivalent to `x.chain(f).alt(y.chain(f))` (distributivity)

### MonadOr

A value that implements the MonadOr specification must also implement
the [MonadZero](#monadzero) specification.

1. `M.of(a).alt(b)` is equivalent to `M.of(a)` (left catch)

### Extend

1. `w.extend(g).extend(f)` is equivalent to `w.extend(_w => f(_w.extend(g)))`
Expand Down
2 changes: 0 additions & 2 deletions internal/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

const patch = require('./patch');
const Maybe = require('./maybe');
const Id = require('./id');
const Sum = require('./string_sum');
const Compose = require('./compose');
const {equality} = require('./func');

module.exports = {
Maybe,
Id,
Sum,
Compose,
Expand Down
51 changes: 0 additions & 51 deletions internal/maybe.js

This file was deleted.

8 changes: 5 additions & 3 deletions internal/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = () => {
return this.length === y.length && this.join('') === y.join('');
};
Array.prototype[fl.map] = Array.prototype.map;
Array.prototype[fl.ap] = function(fs) {
return fs[fl.chain](f => this.map(f));
};
Array.prototype[fl.chain] = function(f) {
return [].concat(this.map(f));
};
Expand All @@ -19,9 +22,8 @@ module.exports = () => {
p([])
);
};
// Array is MonadPlus but not MonadOr
Array.prototype[fl.alt] = function(b) {
return this.length > 0 ? this : b;
return this.concat(b);
};
Array.prototype[fl.zero] = () => [];
Array[fl.zero] = () => [];
};
18 changes: 0 additions & 18 deletions laws/monador.js

This file was deleted.

18 changes: 0 additions & 18 deletions laws/monadplus.js

This file was deleted.

18 changes: 0 additions & 18 deletions laws/monadzero.js

This file was deleted.

31 changes: 8 additions & 23 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const fl = require('.');
const {Id, Maybe, equality, Sum, patch} = require('./internal');
const {Id, equality, Sum, patch} = require('./internal');
patch();

const alt = require('./laws/alt');
Expand All @@ -15,9 +15,6 @@ const extend = require('./laws/extend');
const foldable = require('./laws/foldable');
const functor = require('./laws/functor');
const monad = require('./laws/monad');
const monadOr = require('./laws/monador');
const monadPlus = require('./laws/monadplus');
const monadZero = require('./laws/monadzero');
const monoid = require('./laws/monoid');
const plus = require('./laws/plus');
const semigroup = require('./laws/semigroup');
Expand All @@ -30,16 +27,16 @@ const test = f => t => {
};

exports.alt = {
associativity: test(x => alt.associativity(equality)(Maybe.Nothing)(Maybe.Just(x))(Maybe.Nothing)),
distributivity: test(x => alt.distributivity(equality)(Maybe.Nothing)(Maybe.Just(x))(a => [a])),
associativity: test(x => alt.associativity(equality)(Array[fl.zero]())([x])(Array[fl.zero]())),
distributivity: test(x => alt.distributivity(equality)(Array[fl.zero]())([x])(a => [a])),
};

exports.alternative = {
distributivity: test(
x => alternative.distributivity(equality)(Maybe.Just(x))(Maybe.Nothing)(Maybe.Just(a => [a]))
x => alternative.distributivity(equality)([x])(Array[fl.zero]())([a => [a]])
),
annihilation: test(
x => alternative.annihilation(Maybe)(equality)(Maybe.Just(x))
x => alternative.annihilation(Array)(equality)([x])
),
};

Expand Down Expand Up @@ -92,21 +89,9 @@ exports.monad = {
};

exports.plus = {
rightIdentity: test(x => plus.rightIdentity(Maybe)(equality)(Maybe.Just(x))),
leftIdentity: test(x => plus.leftIdentity(Maybe)(equality)(Maybe.Just(x))),
annihilation: test(x => plus.annihilation(Maybe)(equality)(a => [a])),
};

exports.monadZero = {
annihilation: test(x => monadZero.annihilation(Maybe)(equality)(a => Maybe.Just(a))),
};

exports.monadPlus = {
distributivity: test(x => monadPlus.distributivity(equality)([])([x])(a => a.length === 0 ? [] : [a])),
};

exports.monadOr = {
leftCatch: test(x => monadOr.leftCatch(Maybe)(equality)(x)(Maybe.Nothing)),
rightIdentity: test(x => plus.rightIdentity(Array)(equality)([x])),
leftIdentity: test(x => plus.leftIdentity(Array)(equality)([x])),
annihilation: test(x => plus.annihilation(Array)(equality)(a => [a])),
};

exports.monoid = {
Expand Down

0 comments on commit 00fabbb

Please sign in to comment.