sanmai/pipeline
sanmai/pipeline is a lightweight PHP pipeline library to process data through a chain of stages. Compose reusable, testable transformations with clear input/output flow, and plug in custom middleware-like steps for flexible processing in any app.
Helper functions provide a convenient, fluent syntax for creating pipeline instances.
map()Creates a pipeline from a generator function or a single value.
Signature: map(?callable $func = null): Standard
$func: An optional generator function.Behavior:
$func is a generator, the pipeline is populated with the yielded values.$func returns a single value, the pipeline will contain that one element.Examples:
use function Pipeline\map;
// From a generator
$pipeline = map(function () {
for ($i = 1; $i <= 3; $i++) {
yield $i;
}
});
// From a single value
$pipeline = map(fn() => 'Hello'); // Contains ['Hello']
take()Creates a pipeline from one or more iterables.
Signature: take(?iterable $input = null, iterable ...$inputs): Standard
$input: The primary data source....$inputs: Additional data sources to append.Examples:
use function Pipeline\take;
// From a single array
$pipeline = take([1, 2, 3]);
// From multiple sources
$pipeline = take([1, 2], new ArrayIterator([3, 4]));
fromArray()Creates a pipeline from an array, offering better type safety if you specifically need to handle an array.
Signature: fromArray(array $input): Standard
Examples:
use function Pipeline\fromArray;
$pipeline = fromArray(['a' => 1, 'b' => 2]);
fromValues()Creates a pipeline from a sequence of individual values.
Signature: fromValues(...$values): Standard
Examples:
use function Pipeline\fromValues;
$pipeline = fromValues(1, 'a', true);
zip()Combines multiple iterables into a single pipeline of tuples.
Signature: zip(iterable $base, iterable ...$inputs): Standard
Behavior:
null.Examples:
use function Pipeline\zip;
$names = ['Alice', 'Bob'];
$ages = [30, 25];
$result = zip($names, $ages)->toList();
// [['Alice', 30], ['Bob', 25]]
How can I help you explore Laravel packages today?