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
const daggy = require('daggy') | |
const compose = (f, g) => x => f(g(x)) | |
const id = x => x | |
const kleisli_comp = (f, g) => x => f(x).chain(g) | |
//=============FREE============= | |
const Free = daggy.taggedSum({Impure: ['x', 'f'], Pure: ['x']}) | |
const {Impure, Pure} = Free |
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
const daggy = require('daggy'); | |
const {foldMap} = require('pointfree-fantasy') | |
const {concat, toUpper, prop, identity, range, compose} = require('ramda'); | |
// Contravariant functors usually have this shape F(a -> ConcreteType). | |
// In other words, some type holding a function which is parametric on its input, but not output. | |
// They don't always have that shape, but it's a good intuition | |
// Covariant functors are what we're used to, which are parametric in their output | |
//================================================================ |
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
const daggy = require('daggy') | |
const compose = (f, g) => x => f(g(x)) | |
const id = x => x | |
//===============Define Coyoneda========= | |
const Coyoneda = daggy.tagged('x', 'f') | |
Coyoneda.prototype.map = function(f) { | |
return Coyoneda(this.x, compose(f, this.f)) | |
} |
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
const daggy = require('daggy') | |
const {compose, curry, map, prop, identity, intersection, union} = require('ramda'); | |
const inspect = (x) => { if(!x) return x; return x.inspect ? x.inspect() : x; } | |
// F-algebras | |
// Fix | |
// ============ | |
// Fx is a simple wrapper that does almost nothing. It's much more useful in typed languages to check that we have a recursive f (Fix f) |
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
const compose = (f, g) => x => f(g(x)) | |
const Id = x => | |
({ | |
fold: f => f(x), | |
map: f => Id(f(x)) | |
}) | |
Id.of = Id | |
const Tuple = (_1, _2) => |
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
const Immutable = require('immutable-ext') | |
const {Just, Nothing} = require('data.maybe') | |
const Task = require('data.task') | |
// Setup | |
const Reader = f => | |
({ | |
run: f, | |
map: g => Reader(x => g(f(x))), |
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
import {StateT} from 'fantasy-states' | |
import Task from 'data.task' | |
import {prop, compose, map, chain, merge, always} from 'ramda' | |
// Unfortunately Binary Gendered Baby Page | |
//========================================== | |
// data App a b c = App State a (Task b c) | |
const App = StateT(Task) | |
const {get, put, modify} = App; |
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
// Simple example, but the idea holds for more complex objects. | |
/* 1) Start with OO */ | |
// user.js | |
class User { | |
constructor(firstName, lastName, email) { | |
this.firstName = firstName | |
this.lastName = lastName |
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
const {Map} = require('immutable-ext') | |
const Id = require('fantasy-identities') | |
const Task = require('data.task') | |
const defs = { | |
Band: { | |
dino_jr: { | |
name: 'Dinosaur Jr', | |
members: 3, | |
}, |
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
// http://www.haskellforall.com/2013/02/you-could-have-invented-comonads.html | |
const daggy = require('daggy'); | |
const {toUpper, prop, identity, range, curry, compose} = require('ramda'); | |
const Config = daggy.tagged("opts") | |
Config.prototype.inspect = function() { | |
return `Config(${this.opts})` | |
} |
NewerOlder