pisc/genflow

Generator utilities library

1.0.1 2024-10-09 19:54 UTC

This package is auto-updated.

Last update: 2024-10-29 09:54:46 UTC


README

Library to easily map, filter and reduce on a Generator.

Install

composer require pisc/genflow

Usage

<?php

namespace MyNamespace;

use function Pisc\GenFlow\gen;

function myGenerator()
{
    yield 1;
    yield 2;
    yield 3;
}

gen(myGenerator())
    ->map(fn ($item) => $item * 2)
    ->filter(fn ($item) => $item < 5)
    ->toArray(); // [2, 4]