Skip to content

Instantly share code, notes, and snippets.

View richdouglasevans's full-sized avatar
✌️

Rich richdouglasevans

✌️
  • Oxford, England
View GitHub Profile
@richdouglasevans
richdouglasevans / bifunctor-profunctor.js
Last active November 1, 2018 09:00 — forked from i-am-tom/bifunctor-profunctor.js
The main examples from the "Bifunctor + Profunctor" post.
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 November 1, 2018 09:00 — forked from i-am-tom/Comonad.js
Code for Game of Life from the Comonad article.
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 November 1, 2018 09:00 — forked from i-am-tom/extend.js
All the example code from the Extend article of Fantas, Eel, and Specification.
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 November 1, 2018 09:00 — forked from i-am-tom/monad.js
The Monad example from the Fantasy Land series.
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 November 1, 2018 09:00 — forked from i-am-tom/chainRec.js
Code from the fantas-eel post on ChainRec.
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 August 24, 2017 15:16 — forked from i-am-tom/chain.js
The example code from the `Chain` post!
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 August 24, 2017 14:27 — forked from i-am-tom/semigroup.js
Fantas, Eel, and Specification
import { tagged } from "daggy";
const First = tagged("First", ["val"]);
First.prototype.concat = function(that) {
return this;
};
const Min = tagged("Min", ["val"]);
function repeat(operation, num) {
if (num <= 0) {
return;
}
operation();
return function() {
return repeat(operation, --num);
};
}