simones / partial
Function partial application
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/simones/partial
Requires
- php: >=5.5.0
Requires (Dev)
- mockery/mockery: dev-master
- phpspec/phpspec: ^3.0
This package is not auto-updated.
Last update: 2025-10-12 01:03:00 UTC
README
Apply partial arguments to your functions.
Install
$ composer require simones/partial
Usage
Bind a subset of a function's arguments and get a new function back that accepts the remaining arguments. It is most useful if you write functional programming or don't like using use
with anonymous functions.
You can get a Partial
instance via instantiation or with the partial
helper.
Here are some examples (for more, head to the spec):
// one-argument binding $hello = partial('printf', ['Hello, %s']); $hello('world') // print "Hello, world" // or $hello->call('world') // multiple arguments binding $countdown = partial('printf', ['%s, %s, %s, go!', 'Three']); $countdown('Two', 'One'); // print "Three, Two, One, go!" // you can skip argument, and they will be filled on call time $countdown = partial('printf', ['%s, %s, %s, go!', Partial::SKIP, 'Two']); $countdown('Trhee', 'One'); // print "Three, Two, One, go!"