moirei/pipeline

Simple Laravel pipeline library.

0.2.0 2022-12-17 03:06 UTC

This package is auto-updated.

Last update: 2024-04-23 08:06:46 UTC


README

Amongst several pipeline packages, including Laravel's very own package, you might want a solution with a bit more regor for complex operations.

This package is intended for data processing and should not be a replacement for actions nor jobs. The concept of a pipeline here is a structured collection of micro tasks that happen in succession in order to yield a single output from a single input.

Documentation

All documentation is available at the documentation site.

Features

  • Utility operators
  • Pipeline context
  • Use closures, handler classes or context methods

Example

If you're used to RxJs, you might have an appreciation for the below example. There's technically no limit to what can be done with pipelines.

$value = Pipeline::with(0)->pipe([
    Pipeline::switch([
        fn ($v) => $v + 1,
        fn ($v) => $v + 2,
        fn ($v) => $v + 3,
    ]),
    Pipeline::map(
        fn ($v) => $v * 2,
    ),
    Pipeline::tap(function (array $value) {
        // do whatever
    }),
]);

// returns [2, 4, 6]

See rationale for a more exciting example.

Installation

composer require moirei/pipeline

Tests

composer test

Credits