┌───────────────┐
│ Expression │
│ root: true │
│ globalIdx: 1 │
└───────┬───────┘
parentSeq │ ▲
│ │ expr
┌──────────────┐ ┌───────┴─┴─────┐
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 parserate from '@iter-tools/parserate'; | |
const t = { | |
token: (value) => ({ type: 'token', value }), | |
literal: (value) => ({ type: 'literal', value }), | |
}; | |
const escapes = { | |
'"': '"', | |
'\\': '\\', |
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 t = { | |
token: (value) => ({ type: 'token', value }), | |
literal: (value) => ({ type: 'literal', value }), | |
}; | |
const escapes = { | |
'"': '"', | |
'\\': '\\', | |
b: '\b', | |
f: '\f', | |
n: '\n', |
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 peekerate from '@iter-tools/peekerate'; | |
export function* tokenize(input) { | |
const peekr = peekerate(input); | |
while (!peekr.done) { | |
const char = peekr.value; | |
if (char === '"') { | |
// yields three tokens: " content " | |
yield* tokenizeString(peekr); |
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
┌───────────────┐ | |
│ Expression │ | |
│ root: true │ | |
│ globalIdx: 1 │ | |
└───────┬───────┘ | |
parentSeq │ ▲ | |
│ │ expr | |
┌──────────────┐ ┌───────┴─┴─────┐ | |
│ State │ │ State │ | |
│ type: cont │ │ type: success │ |
Node packages usually ship with scripts that are useful to developers. Common scripts might be build
, test
, or lint
, but you will need to look inside the package.json
file to see what scripts are actually available for a particular package. Here is what a common package with a build
script might look like:
{
"name": "my-package",
"version": "0.1.0",
"scripts": {
"build": "transpile -f lib/index.ts -o /lib/index.js"
},
"devDependencies": {
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
class Builder { | |
*ensure(...tokens) { | |
for (const token of tokens) { | |
yield* token.type === 'Thunk' ? token.ensure(this) : this.advance(token); | |
} | |
} | |
*allow(...tokens) { | |
for (const token of tokens) { | |
yield* token.type === 'Thunk' ? token.allow(this) : this.advance(token, true); |
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
function sum(arr) { | |
let acc = 0; | |
for (let i = 0; i < arr.length; i++) { | |
acc += arr[i].val; | |
} | |
return acc; | |
} | |
const array1 = []; | |
const array2 = []; |
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
/* | |
Lamps often have on-off switches that twist clockwise, clicking as they do. | |
Some such switches have four states, even though the lamp has only two (on, and off). | |
On these lamps clicking the switch will only cause an on/off transition every other click. | |
Just looking at the lamp you'll know if it's on, but not if the next click will turn it off. | |
To reliably interact with such a lamp you will use an algorithm, even in real life. | |
I use the term strategy to refer to an algorithm expressed with generators like this -- | |
the strategy pattern is useful to abstract an algorithm from the representation of the data. | |
For more about lamps: https://temperaturemaster.com/why-does-it-take-two-clicks-to-turn-on-a-lamp/ |