simones / partial
部分应用函数
1.0.0
2016-09-17 17:15 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- mockery/mockery: dev-master
- phpspec/phpspec: ^3.0
This package is not auto-updated.
Last update: 2024-09-14 18:26:20 UTC
README
将部分参数应用于您的函数。
安装
$ composer require simones/partial
用法
绑定函数的部分参数,并返回一个新的函数,该函数接受剩余的参数。如果您编写函数式编程或不喜欢在匿名函数中使用 use
,这将非常有用。您可以通过实例化或使用 partial
辅助函数来获取 Partial
实例。
以下是一些示例(更多示例请参阅规范)
// 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!"