2017 © Pedro Peláez
 

library transformer

image

pitchart/transformer

  • Monday, March 5, 2018
  • by pitchart
  • Repository
  • 1 Watchers
  • 0 Stars
  • 584 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 7 Open issues
  • 9 Versions
  • 71 % Grown

The README.md

Transformer

A transducers implementation in PHP, with OOP powers, (*1)

This package has been inspired by libraries provided by other languages, like clojure's transducers or JAVA Stream API., (*2)

Why ?

Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and specify only the essence of the transformation in terms of an individual element. Because transducers are decoupled from input or output sources, they can be used in many different processes - collections, streams, channels, observables, etc. Transducers compose directly, without awareness of input or creation of intermediate aggregates., (*3)

More information on the clojure reference, (*4)

With classical pipeline pattern, the whole collection is iterated for each step of the transformation and creates an intermediate collection which is a massive waste in memory usage., (*5)

Transducers use functional composition to reduce the number of iterations made while applying transformation., (*6)

Installation

composer require pitchart/transformer

Usage

A transformation consists in a pipeline of transformation functions, called Reducers, ended by a reducing function, aka Termination., (*7)

use function Pitchart\transform;

transform([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
    ->filter(function (int $integer) { return $integer % 2 === 0;})    // [0, 2, 4, 6, 8, 8, 6, 4, 2, 0]
    ->map(function (int $integer) { return $integer + 1; })    // [1, 3, 5, 7, 9, 9, 7, 5, 3, 1]
    ->dedupe()    // [1, 3, 5, 7, 9, 9, 7, 5, 3, 1]
    ->distinct()    // [1, 3, 5, 7, 9]
    ->take(3)     // [1, 3, 5]
    ->sum()    // 9
;

API documentation

"Functional patterns" used by the library are discribed in the Reducers documentation, (*8)

Credits

Licence

The MIT License (MIT). See License file for more information., (*9)

The Versions

05/03 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

05/03 2018

v1.2.0

1.2.0.0

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

05/03 2018

dev-feature/sort

dev-feature/sort

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

05/03 2018

v1.1.1

1.1.1.0

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

05/03 2018

dev-fix/string-termination

dev-fix/string-termination

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

22/02 2018

dev-feature/tests-fixtures

dev-feature/tests-fixtures

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

22/02 2018

dev-feature/immutability-tests

dev-feature/immutability-tests

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

22/02 2018

v1.1.0

1.1.0.0

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE

18/02 2018

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Julien VITTE