2017 © Pedro Peláez
 

library piper

Helps functional programming in OO style.

image

yuyat/piper

Helps functional programming in OO style.

  • Thursday, October 9, 2014
  • by yuya-takeyama
  • Repository
  • 1 Watchers
  • 3 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yuyat\Piper

Helps functional programming in OO style., (*1)

It is recommended to combine this library with other functional libraries like iter., (*2)

Usage

Basic Piper

<?php
use yuyat\Piper;

use function iter\fn\operator;
use function iter\range;

$result = Piper::from(range(1, 10))
    ->pipe('iter\map', [operator('*', 2)])
    ->pipe(function ($iter) { return reduce(operator('+'), $iter, 0); })
    ->get();

echo $result, PHP_EOL;
// => 110

Your custom Piper

<?php
use yuyat\Piper;

use function iter\fn\operator;
use function iter\range;
use function iter\map;
use function iter\reduce;

class IterPiper extends Piper
{
    public function map($fn)
    {
        return new static(map($fn, $this->get()));
    }

    public function reduce($fn, $initial = null)
    {
        return new static(reduce($fn, $this->get(), $initial));
    }
}

$result = IterPiper::from(range(1, 10))
    ->map(operator('*', 2))
    ->reduce(operator('+'), 0)
    ->get();

echo $result, PHP_EOL;
// => 110

Author

Yuya Takeyama, (*3)

The Versions

09/10 2014

dev-master

9999999-dev

Helps functional programming in OO style.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

09/10 2014

v0.0.1

0.0.1.0

Helps functional programming in OO style.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires