Fork

Fork ( array $functions )

Sends every input value to every inner function. Output is the output of every inner function.

Parameters

functions
An array of Pipeline functions. If any of the elements in the array is an array it will be passed as argument to Compose, which is then used as the function.

Examples

Example #1

Basic usage example.

<?php
use Webbhuset\Pipeline\Constructor as F;

$fork = F::Fork([
    F::Map(function ($value) {
        return $value * 2;
    }),
    F::Map(function ($value) {
        return str_repeat('a', $value);
    }),
]);

$input = [1, 2, 3, 4, 5];

echo json_encode(iterator_to_array($fork($input)));

// Output: [2,"a",4,"aa",6,"aaa",8,"aaaa",10,"aaaaa"]

See Also

  • Compose - Chain functions together sequentially.
  • Multiplex - Send every input value to one function based on a callback function.