PHP code example of webbhuset / pipeline

1. Go to this page and download the library: Download webbhuset/pipeline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webbhuset / pipeline example snippets




use Webbhuset\Pipeline\Constructor as F;

$fun = F::Compose([
    F::Map('trim'),
    F::Filter('is_numeric'),
    F::Map('intval'),
    F::Drop(2),
    F::Multiplex(
        function ($value) {
            return $value % 10 == 0 ? 'divide' : 'double';
        },
        [
            'divide' => F::Map(function ($value) {
                return $value / 10;
            }),
            'double' => F::Map(function ($value) {
                return $value * 2;
            }),
        ]
    )
]);

$input = [
    1,
    '  23 ',
    'hello',
    '4.444',
    5.75,
    '+12e3'
];

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

// Output: [8,10,1200]