Skip to content

Commit

Permalink
reinstate identity law
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Dec 31, 2017
1 parent a76b6ab commit 7a2c09f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ A value which has a Group must provide an `invert` method. The
### Filterable

1. `v.filter(x => p(x) && q(x))` is equivalent to `v.filter(p).filter(q)` (distributivity)
2. `v.filter(x => false)` is equivalent to `w.filter(x => false)`
2. `v.filter(x => true)` is equivalent to `v` (identity)
3. `v.filter(x => false)` is equivalent to `w.filter(x => false)`
if `v` and `w` are values of the same Filterable (annihilation)

#### `filter` method
Expand Down
11 changes: 9 additions & 2 deletions laws/filterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {filter} = require('..');
### Filterable
1. `v.filter(x => p(x) && q(x))` is equivalent to `v.filter(p).filter(q)` (distributivity)
2. `v.filter(x => false)` is equivalent to `w.filter(x => false)`
2. `v.filter(x => true)` is equivalent to `v` (identity)
3. `v.filter(x => false)` is equivalent to `w.filter(x => false)`
if `v` and `w` are values of the same Filterable (annihilation)
**/
Expand All @@ -18,10 +19,16 @@ const distributivity = eq => v => p => q => {
return eq(a, b);
};

const identity = eq => v => {
const a = v[filter](x => true);
const b = v;
return eq(a, b);
};

const annihilation = eq => v => w => {
const a = v[filter](x => false);
const b = w[filter](x => false);
return eq(a, b);
};

module.exports = {distributivity, annihilation};
module.exports = {distributivity, identity, annihilation};

0 comments on commit 7a2c09f

Please sign in to comment.