Skip to content

Instantly share code, notes, and snippets.

@spitz-dan-l
spitz-dan-l / update.ts
Last active April 26, 2019 19:49
update.ts - Concise, typed immutable updates to deeply-nested objects
/*
update.ts - Concise, typed immutable updates to deeply-nested objects
Daniel Spitz
Use it like this:
import {update} from 'update';
let obj = { a: 3, b: 'horse', c: { d: [1,2,3] }};
let obj2 = update(obj, { a: 0, c: { d: _ => [..._, 4] } });
@spitz-dan-l
spitz-dan-l / demo_parser_styles.ts
Last active June 28, 2019 14:50
Demo different parser styles
// This is what imperative style looks like when the parser is
// implemented with exceptions for control flow
function imperative_style_with_exceptions(p: Parser) {
p.consume('look at'); // could throw NoMatch
let who = p.split([ // could throw Split or NoMatch
() => p.consume('me', 'me'),
() => p.consume('mewtwo', 'mewtwo'),
() => p.consume('steven', 'steven'),
() => p.consume('martha', 'martha')