2017 © Pedro Peláez
 

library lazy-collection

image

praswicaksono/lazy-collection

  • Wednesday, March 9, 2016
  • by Atriedes
  • Repository
  • 1 Watchers
  • 4 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Lazy Collection

Build Status, (*1)

This collection implement nikic/iter to provide lazy initialization and operation by using Generator, (*2)

Installation

composer require praswicaksono/lazy-collection dev-master, (*3)

Usage

Construct From Generator

$iterable = function () {
    for ($i = 1; $i <= 5; $i++) {
        yield $i;
    }
};

$collection = IterableCollection::fromGenerator($iterable());

Construct From Array

$collection = IterableCollection::fromArray([1, 2, 3, 4, 5]);

Example Usage

$iterable = function () {
    for ($i = 1; $i <= 5; $i++) {
        yield $i;
    }
};

$result = IterableCollection::fromGenerator($iterable())
    ->map(function ($value) {
        return $value * 10;
    })
    ->filter(function ($value) {
        return $value > 30;
    })
    ->reduce(function ($acc, $value, $startValue) {
        return $acc + $value;
    });

// $result = 90

For more information, checkout the test suite., (*4)

Contribute

PRs are welcome!, (*5)

License

MIT, (*6)

The Versions

09/03 2016

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Prasetyo Wicaksono