Sequence

sequence~ Sequence

Source:

Trait for any it­er­able type.

Uses the Sym­bol.iter­ator Sym­bol, so this is im­ple­men­ted for any type that im­ple­ments the iter­ator pro­tocol.

You gen­er­ally won't want to use this, im­ple­ment the iter­ator pro­tocol in­stead.

const { stric­tEqual: as­sertIs } = re­quire('assert');
const { Se­quence, iter, as­ser­tEquals } = re­quire('fer­rum');

// Se­quence ex­tends the iter­ator pro­tocol; they use the same
// sym­bols
as­sertIs(Se­quence.sym, Sym­bol.iter­ator)

// Usu­ally you want to im­ple­ment the Se­quence trait by im­ple­ment­ing
// the iter­ator pro­tocol.
class Foo {
  [Sym­bol.iter­ator]() {
    func­tion* gen() {
      yield 2;
      yield 3;
      yield 4;
    }
    re­turn gen();
  }
};

// You can use iter() as a short­hand for get­ting the iter­ator.
// It is much less cum­ber­some than us­ing mySeq[Sym­bol.iter­ator]().
it = iter(new Foo());
as­ser­tEquals(it.next(), { value: 2, done: false });
as­ser­tEquals(it.next(), { value: 3, done: false });
as­ser­tEquals(it.next(), { value: 4, done: false });
as­ser­tEquals(it.next(), { value: un­defined, done: true });