2017 © Pedro Peláez
 

library lib-helper-pipe

A PHP implementation of the Shell Pipe (|) concept

image

emeraldinspirations/lib-helper-pipe

A PHP implementation of the Shell Pipe (|) concept

  • Tuesday, September 5, 2017
  • by emeraldinspirations
  • Repository
  • 0 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

emeraldinspirations logo, (*1)

lib-helper-pipe

A helper in emeraldinspiration's library., (*2)

A PHP implementation of the Shell Pipe | concept, (*3)

Inspired by: - PHP RFC: Pipe Operator - Shell's Pipe | Operator - Javascript's Promise API, (*4)

PHP does not yet have a syntax for piping the output of one function into the input of another function without nesting the call:, (*5)

<?php

return new \ArrayObject(
    [
        implode(
            '',
            array_reverse(
                str_split(
                    strtoupper(
                        'test string'
                    )
                )
            )
        )
    ]
);

This is messy, and hard to read. Plus it puts the functions in reverse order., (*6)

This class provides an alternate option. It allows using the this function to crate a cleaner looking pipe from one function to another:, (*7)

<?php

use emeraldinspirations\library\helper\pipe\Pipe;

return (new Pipe('test string'))
    ->to('strtoupper')
    ->thenTo('str_split')
    ->thenTo('array_reverse')
    ->thenTo(
        Pipe::delegateWithParamMask('implode', ['', Pipe::here()])
    )
    ->thenTo(
        function ($Param) {
            return [$Param];
        }
    )
    ->thenTo(
        Pipe::delegateConstructor(\ArrayObject::class)
    )
    ->return();

Installing / Getting started

This project has no dependencies, so can simply be required with composer, (*8)

composer require emeraldinspirations/lib-helper-pipe

Future Features

In the example above there is the need to prepend a parameter to the implode function. A future feature may include some way to add additional parameters to thenTo calls., (*9)

<?php

// Example with (callable $Function, array $Prepend = [], array $Append = [])
    // ...
    ->thenTo('implode', [''], [])
    // ...


// Example with (callable $Function, array $ParameterMask = [self::Here])
    // ...
    ->thenTo('implode', ['', Pipe::Here])
    // ...

Licensing

The code in this project is licensed under MIT license., (*10)

The Versions

05/09 2017

dev-master

9999999-dev

A PHP implementation of the Shell Pipe (|) concept

  Sources   Download

MIT

by Matthew "Juniper" Barlett

05/09 2017

1.1.1

1.1.1.0

A PHP implementation of the Shell Pipe (|) concept

  Sources   Download

MIT

by Matthew "Juniper" Barlett

05/09 2017

1.0.1

1.0.1.0

A PHP implementation of the Shell Pipe (|) concept

  Sources   Download

MIT

by Matthew "Juniper" Barlett

05/09 2017

1.0.0

1.0.0.0

A PHP implementation of the Shell Pipe (|) concept

  Sources   Download

MIT

by Matthew "Juniper" Barlett