'use strict';

const {identity, compose} = require('fantasy-combinators');
const {map} = require('..');

/*

### Functor

1. `u.map(a => a)` is equivalent to `u` (identity)
2. `u.map(x => f(g(x)))` is equivalent to `u.map(g).map(f)` (composition)

*/

const identityʹ = t => eq => x => {
    const a = t(x)[map](identity);
    const b = t(x);
    return eq(a, b);
};

const composition = t => eq => x => {
    const a = t(x)[map](compose(identity)(identity));
    const b = t(x)[map](identity)[map](identity);
    return eq(a, b);
};

module.exports = { identity: identityʹ
                 , composition 
                 };
'use strict';

const {map} = require('..');

/*

### Functor

1. `u.map(a => a)` is equivalent to `u` (identity)
2. `u.map(x => f(g(x)))` is equivalent to `u.map(g).map(f)` (composition)

*/

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

const composition = of => eq => x => f => g => {
    const a = of(x)[map](x => f(g(x)));
    const b = of(x)[map](g)[map](f);
    return eq(a, b);
};

module.exports = { identity
                 , composition
                 };

fix composition (#173)