Skip to content

Pipeline is a PHP library for building reusable functions for manipulating values.

License

Notifications You must be signed in to change notification settings

webbhuset/pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipeline

Documentation Status License: MIT

Pipeline is a PHP library for building reusable functions for manipulating values. Every Pipeline function is a class implementing __invoke(), thus allowing instances to be run as functions. Every function takes a Traversable as input and returns a Generator.

Documentation

Documentation is available at ReadTheDocs.

Example

<?php

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]

About

Pipeline is a PHP library for building reusable functions for manipulating values.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages