'use strict';

const {identity, apply} = require('fantasy-combinators');
const {of, chain} = require('..');

/**

### Monad

1. `m.of(a).chain(f)` is equivalent to `f(a)` (left identity)
2. `m.chain(m.of)` is equivalent to `m` (right identity)

**/

const leftIdentity = t => eq => x => {
    const a = t[of](x)[chain](identity);
    const b = identity(x);
    return eq(a, b);
};

const rightIdentity = t => eq => x => {
    const a = t[of](x)[chain](t[of]);
    const b = t[of](x);
    return eq(a, b);
};

module.exports = { leftIdentity
                 , rightIdentity 
                 };
@@ -12,66 +12,8 @@
 ';%0A%0A
-const %7Bidentity, apply%7D = require('fantasy-combinators');%0A
 cons
@@ -43,16 +43,16 @@
 ('..');%0A
+
 %0A/**%0A%0A##
@@ -213,32 +213,37 @@
  t =%3E eq =%3E x =%3E
+ f =%3E
  %7B%0A    const a =
@@ -259,24 +259,17 @@
 %5Bchain%5D(
-identity
+f
 );%0A    c
@@ -277,24 +277,17 @@
 nst b = 
-identity
+f
 (x);%0A   
@@ -499,17 +499,16 @@
 Identity
- 
 %0A       
@@ -519,8 +519,9 @@
       %7D;
+%0A

fix leftIdentity (#171)