Skip to content

Instantly share code, notes, and snippets.

richdouglasevans richdouglasevans

Block or report user

Report or block richdouglasevans

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@richdouglasevans
richdouglasevans / bifunctor-profunctor.js
Last active Nov 1, 2018 — forked from i-am-tom/bifunctor-profunctor.js
The main examples from the "Bifunctor + Profunctor" post.
View bifunctor-profunctor.js
const { Left, Right } = require("fantasy-eithers");
const daggy = require("daggy");
Function.prototype.map = function(f) {
return x => f(this(x));
};
//- Where everything changes...
const login = user => (user.name == "Tom" ? Right(user) : Left("Boo"));
@richdouglasevans
richdouglasevans / Comonad.js
Last active Nov 1, 2018 — forked from i-am-tom/Comonad.js
Code for Game of Life from the Comonad article.
View Comonad.js
const { tagged } = require("daggy");
const Pair = tagged("Pair", ["_1", "_2"]);
//+ data Store p s = Store (p -> s) p
const Store = tagged("Store", ["lookup", "pointer"]);
Array.prototype.equals = function(that) {
return (
this.length === that.length &&
@richdouglasevans
richdouglasevans / extend.js
Last active Nov 1, 2018 — forked from i-am-tom/extend.js
All the example code from the Extend article of Fantas, Eel, and Specification.
View extend.js
const daggy = require("daggy");
const { uncurryN } = require("wi-jit");
Array.prototype.empty = () => [];
const Sum = daggy.tagged("Sum", ["value"]);
Sum.prototype.concat = function(that) {
return Sum(this.value + that.value);
};
@richdouglasevans
richdouglasevans / monad.js
Last active Nov 1, 2018 — forked from i-am-tom/monad.js
The Monad example from the Fantasy Land series.
View monad.js
const Promise = require("fantasy-promises");
const daggy = require("daggy");
//- Regular `compose` - old news!
//+ compose :: (b -> c)
//+ -> (a -> b)
//+ -> a -> c
const compose = f => g => x => f(g(x));
//- `chain`-sequencing `compose`, fancily
@richdouglasevans
richdouglasevans / chainRec.js
Last active Nov 1, 2018 — forked from i-am-tom/chainRec.js
Code from the fantas-eel post on ChainRec.
View chainRec.js
const daggy = require("daggy");
const { Loop, Done } = daggy.taggedSum("Loop", {
Loop: ["b"],
Done: ["a"]
});
Array.empty = () => [];
const Pair = T => {
@richdouglasevans
richdouglasevans / chain.js
Last active Aug 24, 2017 — forked from i-am-tom/chain.js
The example code from the `Chain` post!
View chain.js
const Option = require("fantasy-options");
const Either = require("fantasy-eithers");
const Task = require("data.task");
const { tagged } = require("daggy");
const { Some, None } = Option;
const { Left, Right } = Either;
const Pair = tagged("Pair", ["_1", "_2"]);
@richdouglasevans
richdouglasevans / semigroup.js
Created Aug 24, 2017 — forked from i-am-tom/semigroup.js
Fantas, Eel, and Specification
View semigroup.js
import { tagged } from "daggy";
const First = tagged("First", ["val"]);
First.prototype.concat = function(that) {
return this;
};
const Min = tagged("Min", ["val"]);
View trampoline.js
function repeat(operation, num) {
if (num <= 0) {
return;
}
operation();
return function() {
return repeat(operation, --num);
};
}
You can’t perform that action at this time.