2017 © Pedro Peláez
 

library copipe-iter

Most simple iterators

image

baguette/copipe-iter

Most simple iterators

  • Friday, May 5, 2017
  • by zonuexe
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 3 % Grown

The README.md

Copipe Iter

Package version Build Status Packagist Coverage Status, (*1)

Most simple iterators., (*2)

I do not claim the right for this project. This package is licensed under WTFPL., (*3)

API

Generator map(iterable $iter, callable $callback)

$data = [1, 2, 3];
$twice = function ($n) { return $n * 2; };

foreach (map($data, $twice) as $a) {
    echo $a, PHP_EOL;
}
// [output] 2, 4, 6

Generator map_kv(iterable $iter, callable $callback)

$data = ['apple', 'orange', 'strawberry'];
$deco = function ($k, $v) { return "{$k}: $v"; };

foreach (map_kv($data, $deco) as $a) {
    echo $a, PHP_EOL;
}
// [output] "1: apple", "2: orange", "3: strawberry"

Generator take(iterable $iter, int $n)

$data = range(1, 100);

foreach (take($data, 5) as $a) {
    echo $a, PHP_EOL;
}
// [output] 1, 2, 3, 4, 5

array to_array(iterable $iter)

$fib = function () {
    $n = 0; yield $n;
    $m = 1; yield $m;

    while (true) {
        $c = $n + $m;
        yield $c;
        $n = $m;
        $m = $c;
    }
};

$fib_10 = to_array(take($fib(), 10));
//=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

The Versions

05/05 2017

dev-master

9999999-dev

Most simple iterators

  Sources   Download

WTFPL

The Requires

  • php >=5.5.0

 

The Development Requires

30/04 2017

0.0.4

0.0.4.0

Most simple iterators

  Sources   Download

WTFPL

The Requires

  • php >=5.5.0

 

The Development Requires

11/08 2016

0.0.3

0.0.3.0

Most simple iterators

  Sources   Download

WTFPL

The Requires

  • php >=5.5.0

 

The Development Requires

10/08 2016

0.0.2

0.0.2.0

Most simple iterators

  Sources   Download

WTFPL

The Requires

  • php >=5.5.0

 

10/08 2016

0.0.1

0.0.1.0

Most simple iterators

  Sources   Download

WTFPL

The Requires

  • php >=5.5.0