This file contains hidden or 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 just = | |
target => | |
input => | |
input.startsWith(target) && | |
target; | |
const cases = | |
(...patterns) => | |
input => { | |
const matches = patterns.map(p => p(input)).filter(m => m !== false); |
This file contains hidden or 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://raganwald.com/2019/01/14/structural-sharing-and-copy-on-write.html | |
// http://raganwald.com/2019/01/26/reduce-reuse-recycle.html | |
// | |
const SliceHandler = { | |
has (slice, property) { | |
if (property in slice) { | |
return true; | |
} |
This file contains hidden or 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 ComposableCarCdr = { | |
has (target, name) { | |
if (name in target) { | |
return true; | |
} | |
if (name === Symbol.isConcatSpreadable) { | |
return true; | |
} | |
This file contains hidden or 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
function scoop(before, fromPit) { | |
const after = before.slice(0); | |
const seedsInHand = after[fromPit]; | |
after[fromPit] = 0; | |
return [after, seedsInHand]; | |
} | |
function nextPit(pit) { |
This file contains hidden or 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
function isBalancedSimple (before) { | |
if (before === '') return true; | |
const after = before.replace('()',''); | |
return (before !== after) && isBalancedSimple(after); | |
} | |
function isBalancedMultiple (before) { | |
if (before === '') return true; |
This file contains hidden or 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
// Prelude: Composeable Functional Pattern Matchers | |
const just = | |
target => | |
input => | |
input.startsWith(target) && | |
target; | |
const cases = | |
(...patterns) => |
This file contains hidden or 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
// Computes the twelve "fundamental" solutions to the eight queens problem | |
// by filtering the results of the "half-inductive" algorithm. | |
// | |
// see http://raganwald.com/2018/08/03/eight-queens.html | |
// | |
// search space: 2,750 candidate positions | |
function testDiagonals (queens) { | |
const nesw = [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."]; | |
const nwse = [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."]; |
This file contains hidden or 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
#Denumerable | |
# Copyright 2002 Reginald Braithwaite-Lee. All Rights Reserved. | |
# http://www.braithwaite-lee.com/tips/denumerables.html | |
module Denumerable | |
#must define :denumerableIteratorFactory, :denumerableIteratorFactory= | |
#initialize must support NO ARGUMENTS |
This file contains hidden or 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
// A state machine that works from a description including explicit transitions, | |
// and can generate a transition map and a digraph | |
const STATES = Symbol("states"); | |
const STARTING_STATE = Symbol("starting-state"); | |
const TRANSITIONS = Symbol("transitions"); | |
const RESERVED = [STARTING_STATE, TRANSITIONS]; | |
const MACHINES_TO_CURRENT_STATE_NAMES = new WeakMap(); | |
const MACHINES_TO_STARTING_STATES = new WeakMap(); |
This file contains hidden or 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
function * multiplesOf (startingWith, n) { | |
let number = startingWith; | |
while (true) { | |
yield number; | |
number = number + n; | |
} | |
} | |
function destructure (iterable) { |