Fetching contributors…
Cannot retrieve contributors at this time
36 lines (21 sloc) 1.02 KB


Fluent interface for function composition.

Methods in FluentFunctions return instance of FluentFunction that contains all functions from :doc:`functions`.

Calls to FluentFunction can be chained. The resultant function calls chained function in the order they were specified.

For example:

$functionC = FluentFunctions::functionA()->functionB();

results in a functionC such that for each argument x functionC(x) == functionB(functionA(x)).


Let's create a function that extracts field 'name' from the given argument, then removes prefix 'super', adds ' extra' at the beginning, appends '! ' and surrounds result with "***".

$function = FluentFunctions::extractField('name')
      ->prepend(' extra')
      ->append('! ')

$product = new Product(array('name' => 'super phone'));

$result = Functions::call($function, $product); //=> '*** extra phone! ***'