stdtraits~ Pairs


Get an iter­ator over a con­tainer.

const { val­ues, keys, pairs, Pairs, as­sertSequenceEquals } = re­quire('fer­rum');

class Bar {
  *[Pairs.sym]() {
    yield ['foo', 42];
    yield ['bar', 5];

as­sertSequenceEquals(pairs(new Bar()),  [['foo', 42], ['bar', 5]]);
as­sertSequenceEquals(keys(new Bar()),   ['foo', 'bar']);
as­sertSequenceEquals(val­ues(new Bar()), [42, 5]);

This is dif­fer­ent from the Se­quence trait in se­quence.js in that this al­ways re­turns pairs, even for lists, sets, strings...


(c: Con­tainer(k: Key, v: Value)) => r: Se­quence([k: Key, v: Value], ...).

Spe­cial­iz­a­tion Notes

Ar­ray like types re­turn in­dex => value, set re­turns value => value.

See: pairs See: keys See: val­ues