ta-tikoma / bind
bind method for binding argument to callable
Installs: 119
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ta-tikoma/bind
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
README
There is only two functions in this package: bind and flip, for make you code short.
Install
composer require ta-tikoma/bind
Examples
Example 1 (Simple)
Before
array_map(static fn (string $s) => substr($s, 2), ['a_bar', 'a_foo', 'a_boo'])
After
array_map(bind(substr(...), 2), ['a_bar', 'a_foo', 'a_boo'])
Example 2 (Pipe)
Before
$result = 'Hello World' |> static fn (string $s) => explode(' ', $s) |> static fn (array $a) => array_filter($a, static fn (string $s) => str_starts_with($s, 'H'))
After
$result = 'Hello World' |> bind(flip(explode(...)), ' ') |> bind(array_filter(...), bind(str_starts_with(...), 'H'))
Example 3 (Collection)
Before
$result = collect(['1', '2', '3'])->map(static fn (string $number) => (int) $number);
After
$result = collect(['1', '2', '3'])->map(bind(intval(...)));