mamazu/partial-functions

There is no license information available for the latest version (1.0.0) of this package.

Applying partial functions

1.0.0 2020-09-29 16:29 UTC

This package is auto-updated.

Last update: 2024-04-06 17:54:07 UTC


README

This library provides a partial function interface for php.

Usage

The simpletest way to use it with the FunctionInvoker:

function f(string $greeting = 'Hello', string $name = 'you') {
    return $greeting.', '.$name;
}

echo \Mamazu\PartialFunctions\FunctionInvoker::invoke('f', ['name' => 'Anonymous']);

// Will echo "Hello, Anonymous"

Object oriented

$factory = new \Mamazu\PartialFunctions\PartialFunctionFactory();
$searchInString = $factory->createForCallable('strpos');
$searchInString->apply(['haystack' => 'Hello in PHP']);

$hellopos = $searchInString->call(['needle' => 'hello']);
$phppos = $searchInString->call(['needle' => 'php']);