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 maybeSelectConsecutiveEntity = editorState => { | |
const selection = editorState.getSelection(); | |
if (!selection.isCollapsed()) { | |
return editorState; | |
} | |
const startKey = selection.getStartKey(); | |
const startOffset = selection.getStartOffset(); | |
const prevOffset = startOffset - 1; |
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 I = x => x | |
const K = x => y => x | |
const A = f => x => f (x) | |
const T = x => f => f (x) | |
const W = f => x => f (x) (x) | |
const C = f => y => x => f (x) (y) | |
const B = f => g => x => f (g (x)) | |
const S = f => g => x => f (x) (g (x)) | |
const S_ = f => g => x => f (g (x)) (x) | |
const S2 = f => g => h => x => f (g (x)) (h (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
import State, {get, put, modify} from 'fantasy-states' | |
import {prop, compose, map, chain, merge, always} from 'ramda' | |
// Unfortunately Binary Gendered Baby Page | |
//========================================== | |
const babies = [{id: 2, name: 'Anjali', sex: 'F'}, {id: 3, name: 'Antonio', sex: 'M'}] | |
// isFemale :: Baby -> Bool |
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
// 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})` | |
} |
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
//https://gist.github.com/quelgar/4661081 | |
const daggy = require('daggy'); | |
const {range} = require('ramda'); | |
// type to hold an index and the array | |
const Pointer = daggy.tagged('i', 'a') | |
// Comonad instance | |
Pointer.prototype.extract = function() { return this.a[this.i] } |
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 lineLens = lens(split('\n'), join('\n')); | |
const mapLines = curry((fn, str) => | |
over(lineLens, map(fn), str)); | |
const adjustLine = curry((fn, n, str) => | |
over(lineLens, adjust(fn, n), str)) | |
mapLines(toUpper, 'foo\nbar') // => 'FOO\nBAR' | |
adjustLine(toUpper, 0, 'foo\nbar') // => 'FOO\nbar" |
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 IdModule = { | |
fmap: (fn) => (x) => fn(x), | |
} | |
const ConstModule = { | |
fmap: (fn) => (x) => 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
console.log("\033[39mRunning tests…"); | |
function assertEquals(actual, expected, description) { | |
if(typeof actual === "undefined") { | |
console.error("\033[31m" + description + " not implemented\033[39m"); | |
} else { | |
if(actual !== expected) { | |
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m"); | |
} else { | |
console.log(description + " \033[32m ok\033[39m"); | |
} |