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
/* | |
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] } }); |
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
// 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') |
OlderNewer