Skip to content

Commit

Permalink
update Extend and Comonad dependencies to match figure
Browse files Browse the repository at this point in the history
This commit also removes the third Comonad law.
  • Loading branch information
davidchambers committed Dec 18, 2016
1 parent 2d88537 commit 11860a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ structures:
* [Bifunctor](#bifunctor)
* [Profunctor](#profunctor)

<img src="figures/dependencies.png" width="888" height="340" />
<img src="figures/dependencies.png" width="888" height="347" />

## General

Expand Down Expand Up @@ -457,6 +457,8 @@ the [Applicative](#applicative) and [Chain](#chain) specifications.

### Extend

A value that implements the Extend specification must also implement the [Functor](#functor) specification.

1. `w.extend(g).extend(f)` is equivalent to `w.extend(_w => f(_w.extend(g)))`

#### `extend` method
Expand All @@ -481,11 +483,10 @@ method takes one argument:

### Comonad

A value that implements the Comonad specification must also implement the [Functor](#functor) and [Extend](#extend) specifications.
A value that implements the Comonad specification must also implement the [Extend](#extend) specification.

1. `w.extend(_w => _w.extract())` is equivalent to `w`
2. `w.extend(f).extract()` is equivalent to `f(w)`
3. `w.extend(f)` is equivalent to `w.extend(x => x).map(f)`

#### `extract` method

Expand Down
11 changes: 2 additions & 9 deletions laws/comonad.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

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

/**
### Comonad
1. `w.extend(_w => _w.extract())` is equivalent to `w`
2. `w.extend(f).extract()` is equivalent to `f(w)`
3. `w.extend(f)` is equivalent to `w.extend(x => x).map(f)`
**/

Expand All @@ -25,10 +24,4 @@ const rightIdentity = t => eq => x => {
return eq(a, b);
};

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

module.exports = {leftIdentity, rightIdentity, associativity};
module.exports = {leftIdentity, rightIdentity};
1 change: 0 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ exports.chainRec = {
exports.comonad = {
leftIdentity: test(comonad.leftIdentity(Id[fl.of])(equality)),
rightIdentity: test(comonad.rightIdentity(Id[fl.of])(equality)),
associativity: test(comonad.associativity(Id[fl.of])(equality)),
};

exports.extend = {
Expand Down

0 comments on commit 11860a5

Please sign in to comment.