-
Notifications
You must be signed in to change notification settings - Fork 5
Matt Bierner edited this page Nov 8, 2015
·
32 revisions
Complete API for Apep
Run a generator to completion, combining results into a string.
-
g
- Generator to run. -
ud
- Optional, user data. -
r
- Optional, custom random number generator.
const p = pep.seq('a', pep.choice('b', 'c'));
p.run() === 'ac';
p.run() === 'ac';
p.run() === 'ab';
Left fold over a generator.
-
f
- Accumulation function, passed accumulated value and current value. -
z
- Initial value. -
g
- Generator to run. -
ud
- Optional, user data. -
r
- Optional, custom random number generator.
const p = pep.seq('a', 'b', 'c');
pep.fold((p, c) => p.concat(c), [], p) === ['a', 'b', 'c'];
Begin the execution of a generator. Returns a Javascript iterator.
-
g
- Generator to run. -
ud
- Optional, user data. -
r
- Optional, custom random number generator.
Values are lazily produced. Javascript iterators are stateful, so you can only iterate over the result of begin
once.
const p = pep.seq('a', 'b', 'c');
for (const x of p.begin())
console.log(x);