- PHP >= 5.4
Flow provides a fluent interface to assemble chains of iterators and other data processing operations.
The fluent API makes it very easy and intuitive to use the native SPL iterators (together with some custom ones provided by this library) and the expressive syntax allows you to assemble sophisticated processing pipelines in an elegant, terse and readable fashion.
An iteration chain assembled with this builder can perform multiple transformations over a data flow without storing in memory the resulting data from intermediate steps. When operating over large data sets, this mechanism can be very light on memory consumption.
Inputs to the chain can be any kind of iterables. Iterables are things that can be converted to iterators.
They can be native arrays, Traversables (classes implementing the native Iterator
or IteratorAggregate
intefaces),
invoked generator functions (on PHP>=5.5) or even callables (ex. Closures).
Flow allows you to write generator functions using common functions on PHP<5.5, using the
FunctionIterator
class.
TODO: provide examples here.
Flow also provides a library of useful iterators that complements and extends the basic set provided by the Standard PHP Library (SPL).
These are the iterators:
Memoizes another iterator's values so that subsequent iterations will not need to iterate it again.
Iterates another iterator until the iteration finishes or the given callback returns false
(whichever occurs first).
Iterates a given iterator swapping keys for values and/or vice-versa.
Iterates over values generated by repeatedly invoking a function or class method.
Allows the looping of another iterator, with some constraints.
Replaces and expands each iterated value of another iterator.
Transforms data from another iterator using a callback function.
Iterates over a generated sequence of numbers.
A generic recursive iterator that defines the recursion via a user-defined callback function.
Applies a function against an accumulator and each value from a given iterator to reduce the iterated data to a single value.
Iterates another iterator replacing keys by a generated sequence of numbers.
Provides one single iteration of a constant value.
Some operations require the iteration data to be "materialized", i.e. fully iterated and stored internally as an array, before the operation is applied. This only happens for operations that require all data to be present (ex:
reverse()
orsort()
), and the resulting data will be automatically converted back to an iterator whenever it makes sense.
This library is open-source software licensed under the MIT license.
Flow - Copyright © 2015 Impactwave, Lda.