Skip to content
Matt Bierner edited this page Nov 8, 2015 · 32 revisions

Complete API for Apep

Execution

run(g, ud, random = Math.random)

g.run(ud, random = Math.random)

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';

fold(f, z, g, ud, random = Math.random)

g.fold(f, z, ud, random = Math.random)

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(g, ud, random = Math.random)

g.begin(ud, random = Math.random)

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);
Clone this wiki locally