friends-of-reactphp / partial Goto Github PK
View Code? Open in Web Editor NEWPartial function application.
License: MIT License
Partial function application.
License: MIT License
Is anyone interested in changes that would package current functionality into a class that is constructed with a callable and an integer for arity? This would let us implement the __invoke magic method to allow lifting the partial by binding passed in arguments and returning $this unless the arity has been reduced to 0, in which case we would actually execute. For example:
$map = new Partial('array_map', 2);
$inc = $map(function($x) { return $x++; });
$inc([1, 2, 3]); // returns [2, 3, 4]
We would reduce the arity by the count of non-placeholder arguments passed in each time:
$sub = new Partial('substr', 3);
$chunk2 = $sub(…, …, 2);
$last2 = $chunk(…, -2);
$last2('lol'); // 'ol'
I suppose you could make the method to execute the internal callable public and default the arity to unbounded, so that it's possible to pass along a filter with array_diff. Someone would just have to call a method at the end like evaluate(), or the previous actor would call something like finalize() which would fix the arity to 0 and fail if there were still any Placeholders.
Comments? I am issuing a request for them.
What about a PHP 5.6 version that uses argument unpacking and direct function invocation. Did that for functional-php and it makes the code significantly nicer (and also slightly faster): lstrojny/functional-php@bfd7cae
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.