2017 © Pedro Peláez
 

library php-iterator

php iterator

image

dgame/php-iterator

php iterator

  • Wednesday, May 31, 2017
  • by Dgame
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12,696 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 14 % Grown

The README.md

php-iterator

Scrutinizer Code Quality Code Coverage Build Status StyleCI Build Status, (*1)

Enjoy high order functions

only & repeat

$this->assertEquals('aaaa', only('a')->repeat(4)->implode());

take

$this->assertEquals('Hal', chars('Hallo')->take(3)->implode());

skip

$this->assertEquals('lo', chars('Hallo')->skip(3)->implode());

slice

$this->assertEquals('oBar', chars('FooBarQuatz')->slice(2, 6)->implode());

chunks

$this->assertEquals([['F', 'o'], ['o', 'B'], ['a', 'r']], chars('FooBar')->chunks(2)->collect());

fold

$it = iter([6, 7, 8]);

$sum1 = function($sum, int $a) {
    return $sum + $a;
};

$sum2 = function(int $sum, int $a) {
    return $sum + $a;
};

$this->assertEquals(21, $it->fold($sum1));
$this->assertEquals(63, $it->fold($sum2, 42));

take while

$belowTen = function (int $item) {
    return $item < 10;
};

$this->assertEquals([0, 1, 2], iter([0, 1, 2, 10, 20])->takeWhile($belowTen)->collect());

skip while

$belowTen = function (int $item) {
    return $item < 10;
};

$this->assertEquals([10, 20], iter([0, 1, 2, 10, 20])->skipWhile($belowTen)->collect());

before

$this->assertEquals('ab', chars('abcdef')->before('c')->implode());
$this->assertEquals(['a' => 'z', 'b' => 'y'], iter(['a' => 'z', 'b' => 'y', 'c' => 'x', 'd' => 'w'])->before('x')->collect());

after

$this->assertEquals('ef', chars('abcdef')->after('d')->implode());
$this->assertEquals(['d' => 'w'], iter(['a' => 'z', 'b' => 'y', 'c' => 'x', 'd' => 'w'])->after('x')->collect());

from

$this->assertEquals('def', chars('abcdef')->from('d')->implode());
$this->assertEquals(['c' => 'x', 'd' => 'w'], iter(['a' => 'z', 'b' => 'y', 'c' => 'x', 'd' => 'w'])->from('x')->collect());

until

$this->assertEquals('abc', chars('abcdef')->until('c')->implode());
$this->assertEquals(['a' => 'z', 'b' => 'y', 'c' => 'x'], iter(['a' => 'z', 'b' => 'y', 'c' => 'x', 'd' => 'w'])->until('x')->collect());

all

$positive = function (int $item) {
    return $item >= 0;
};

$this->assertTrue(iter([0, 1, 2, 3])->all($positive));
$this->assertFalse(iter([-1, 2, 3, 4])->all($positive));

any

$positive = function (int $item) {
    return $item > 0;
};

$this->assertTrue(iter([-1, 0, 1])->any($positive));
$this->assertFalse(iter([-1])->any($positive));

The Versions

31/05 2017

dev-master

9999999-dev https://github.com/php-iterator

php iterator

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

filter array iterator functional traversable high order functions

30/05 2017

v0.3.0

0.3.0.0 https://github.com/php-iterator

php iterator

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

filter array iterator functional traversable high order functions

01/05 2017

v0.2.0

0.2.0.0 https://github.com/php-iterator

php iterator

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

filter array iterator functional traversable high order functions

18/09 2016

v0.1.1

0.1.1.0 https://github.com/php-iterator

php iterator

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

filter array iterator functional traversable high order functions

11/08 2016

v0.1.0

0.1.0.0 https://github.com/php-iterator

php iterator

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

filter array iterator functional traversable high order functions