-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from gabejohnson/add-semigroupoid-and-category
Add Semigroupoid and Category algebras
- Loading branch information
Showing
8 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const {compose, id} = require('..'); | ||
|
||
/** | ||
### Category | ||
1. `a.compose(C.id())` is equivalent to `a` (right identity) | ||
2. `C.id().compose(a)` is equivalent to `a` (left identity) | ||
**/ | ||
|
||
const leftIdentity = f => eq => x => { | ||
const a = f[compose](Function[id]())(x); | ||
const b = f(x); | ||
return eq(a, b); | ||
}; | ||
|
||
const rightIdentity = f => eq => x => { | ||
const a = Function[id]()[compose](f)(x); | ||
const b = f(x); | ||
return eq(a, b); | ||
}; | ||
|
||
module.exports = {leftIdentity, rightIdentity}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const {compose} = require('..'); | ||
|
||
/** | ||
### Semigroupoid | ||
1. `a.compose(b).compose(c)` is equivalent to `a.compose(b.compose(c))` (associativity) | ||
**/ | ||
|
||
const associativity = f => g => h => eq => x => { | ||
const a = f[compose](g)[compose](h)(x); | ||
const b = f[compose](g[compose](h))(x); | ||
return eq(a, b); | ||
}; | ||
|
||
module.exports = {associativity}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters