2017 © Pedro Peláez
 

library itertools

itertools for working with genrators/iterators

image

thesebas/itertools

itertools for working with genrators/iterators

  • Monday, November 6, 2017
  • by thesebas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

thesebas/itertools

Tools to work with iterators. BUILD STATUS Coverage Status, (*1)

Installation

composer require thesebas/itertools, (*2)

Usage

Lest assume we have some generator that yields letters., (*3)

expect(iterator_to_array(gen(3)))->toBe(['a', 'b', 'c']);

tail

Skip all but n items from Iterator., (*4)

$actual = tail(gen(5), 3, false);
expect(iterator_to_array($actual))->toBe(['c', 'd', 'e']);

Iterator over n first items., (*5)

$actual = head(gen(10), 3);
expect(iterator_to_array($actual))->toBe(['a', 'b', 'c']);

skip

Skip n items and iterate over rest., (*6)


$actual = skip(gen(10), 4); expect(iterator_to_array($actual))->toBe(['e', 'f', 'g', 'h', 'i', 'j']);

tee

Split Iterator to two independent Iterators (with internal buffering)., (*7)

list($left, $right) = tee(gen(10));


expect(iterator_to_array(head($left, 3)))->toBe(['a', 'b', 'c']);
expect(iterator_to_array(head($right, 5)))->toBe(['a', 'b', 'c', 'd', 'e']);

expect(iterator_to_array(head($left, 5)))->toBe(['d', 'e', 'f', 'g', 'h']);
expect(iterator_to_array(head($right, 2)))->toBe(['f', 'g']);

expect(iterator_to_array(head($left, 2)))->toBe(['i', 'j']);
expect(iterator_to_array(head($right, 3)))->toBe(['h', 'i', 'j']);

chain

Iterate over first, then second, third..., (*8)

$actual = chain(gen(5), gen(3));
expect(iterator_to_array($actual))->toBe(['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c']);

filter

Iterate ovel all but yield only filtered items., (*9)

$actual = filter(gen(10), function ($item, $key) {
    return $key % 2 == 1;
});
expect(iterator_to_array($actual))->toBe(['b', 'd', 'f', 'h', 'j']);

map

Return new Iterator with mapped values, (*10)


$actual = map(gen(3), function ($item, $key) { return "item {$key}: {$item}"; }); expect(iterator_to_array($actual))->toBe(['item 0: a', 'item 1: b', 'item 2: c']);

chunk

Return iterator of chunk iterators., (*11)

$actual = \iterator_to_array(map(chunk(gen(10), 3), '\\iterator_to_array'));
expect($actual)->toBe([
    ['a', 'b', 'c'],
    ['d', 'e', 'f'],
    ['g', 'h', 'i'],
    ['j']
]);

The Versions

06/11 2017

dev-master

9999999-dev

itertools for working with genrators/iterators

  Sources   Download

MIT

The Development Requires

by Avatar thesebas

06/11 2017

1.0.3

1.0.3.0

itertools for working with genrators/iterators

  Sources   Download

MIT

The Development Requires

by Avatar thesebas

05/11 2017

1.0.2

1.0.2.0

itertools for working with genrators/iterators

  Sources   Download

MIT

The Development Requires

by Avatar thesebas

05/11 2017

1.0.1

1.0.1.0

itertools for working with genrators/iterators

  Sources   Download

MIT

The Development Requires

by Avatar thesebas

05/11 2017

dev-travis

dev-travis

itertools for working with genrators/iterators

  Sources   Download

MIT

The Development Requires

by Avatar thesebas

04/11 2017

1.0

1.0.0.0

itertools for working with genrators/iterators

  Sources   Download

MIT

The Development Requires

by Avatar thesebas