-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds contravariant functor to spec (#150)
* adds contravariant functor to spec * adds to list of structures * Adds type signature; removes contravariant dependency in profunctor * Fix linting errors * Update figures * Update height of img in README * Remove 'functor' from 'Contravariant' section name * Update algebra name in dependencies graph * Should be the last few fixes necessary for merge * Update contramap laws
- Loading branch information
Showing
5 changed files
with
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ digraph { | |
Extend; | ||
Foldable; | ||
Functor; | ||
Contravariant; | ||
Monad; | ||
Monoid; | ||
Plus; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const {identity, compose} = require('fantasy-combinators'); | ||
const {contramap} = require('..'); | ||
|
||
/* | ||
### Contravariant Functor | ||
1. `u.contramap(a => a)` is equivalent to `u` (identity) | ||
2. `u.contramap(x => f(g(x)))` is equivalent to `u.contramap(f).contramap(g)` (composition) | ||
*/ | ||
|
||
const identityʹ = t => eq => x => { | ||
const a = t(x)[contramap](identity); | ||
const b = t(x); | ||
return eq(a, b); | ||
}; | ||
|
||
const composition = t => eq => x => { | ||
const a = t(x)[contramap](compose(identity)(identity)); | ||
const b = t(x)[contramap](identity)[contramap](identity); | ||
return eq(a, b); | ||
}; | ||
|
||
module.exports = {identity: identityʹ, composition}; |