dkulyk/sequence

Lazy sequence library for PHP.

1.0.4 2017-05-23 11:33 UTC

This package is auto-updated.

Last update: 2024-12-21 20:57:50 UTC


README

Quick Example

Install the package via composer by adding this section to the composer.json file:

"require": {
    "dkulyk/sequence": "~1.0"
},

This is a tiny script to get a feeling of how Sequence works.

<?php
require_once __DIR__.'/vendor/autoload.php';

use DKulyk\Sequence\Sequence;

function fibonacci(&$value, $a = 1, $b = 2)
{
    $value = $a;
    return function (&$v) use ($a, $b) {
        return fibonacci($v, $b, $a + $b);
    };
}


$i = (new Sequence('fibonacci'))
    ->limit(10);

foreach ($i as $k => $v) {
    echo $k, ' => ', $v, PHP_EOL;
}

and the output of this program will be:

0 => 1
1 => 2
2 => 3
3 => 5
4 => 8
5 => 13
6 => 21
7 => 34
8 => 55
9 => 89

This is just a tiny bit of all the things that can be accomplished with Sequence.