Global

Methods

flatten(seq, fn) → {Iterator}

Source:

Cut off the se­quence at the first point where the given con­di­tion is no longer met.

list(take­While([1,2,3,4,5,6...], x => x < 4)) yields [1,2,3]

Ver­sion His­tory

  • 2.0.0 Add alias flat­ten()
Parameters:
Name Type Description
seq Sequence

Any se­quence for which iter() is defined

fn function

The pre­dic­ate func­tion

Returns:
Type
Iterator

multiline()

Source:

This is a helper for de­clar­ing mul­til­ine strings.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { mul­til­ine } = re­quire('fer­rum');

as­sertIs(
  mul­til­ine(`
    Foo
    Bar
    Baz

       Hello

    Bang

  `),
  'Foo\nBar\nBaz\n\n   Hello\n\nBang\n');

as­sertIs(
  mul­til­ine(`Foo\nBar`),
  'Foo\nBar');

The func­tion ba­sic­ally just takes a string and then strips the first & last lines if they are empty.

In or­der to re­move in­dent­a­tion, we de­term­ine the com­mon whitespace pre­fix length (num­ber of space 0x20 char­ac­ters at the start of the line). This pre­fix is simply re­moved from each line...

takeShort(seq, no) → {Iterator}

Source:

Yields an iter­ator of the first no ele­ments in the given se­quence; the res­ult­ing iter­ator may con­tain less then no ele­ments if the in­put se­quence was shorter than no ele­ments.

Parameters:
Name Type Description
seq Sequence

Any se­quence for which iter() is defined

no Number

The num­ber of ele­ments to take

Returns:

The first ele­ment for which pred re­turns false plus the rest of the se­quence.

Type
Iterator