grrr-amsterdam / garp-functional Goto Github PK
View Code? Open in Web Editor NEWPHP utility library embracing functional programming paradigms.
License: BSD 3-Clause "New" or "Revised" License
PHP utility library embracing functional programming paradigms.
License: BSD 3-Clause "New" or "Revised" License
Not every function that accepts a callable arguments validates it as such.
It would make the library a little more robust to throw an InvalidArgumentException
for non-callable arguments in those cases.
I think it should be @return array|callable
instead of @return int|callable
(such as a Carbon
instance)
And maybe other functions as well? join
, for instance.
If a class uses __get()
to get to certain properties, prop()
won't follow because it'll detect it being an object and try to read $object->property
.
So, I saw the tags had a v
prefix but 1.0.5 doesn't. I don't think it's really a problem but it's an inconsistency :)
contains($search, $collection);
I recently moved to PHP from JS at my work and I was searching for something like https://github.com/ramda/ramda
Thanks a lot for this, your lib has the best usage and UX from all the functional libs I saw until now
Don't let this die, I'll use it a lot and will try to open a PR if i find something to add here :D
The following object will fail when passed to prop()
:
$arrayAccessObj = new class implements ArrayAccess {
protected $_data = [];
public function offsetExists($offset) {
return isset($this->_data[$offset]);
}
public function offsetGet($offset) {
throw new Exception('Don\'t call get when offset is not set');
}
public function offsetSet($offset, $value) {}
public function offsetUnset($offset) {}
};
It incorrectly passes array_slice(func_get_args(), 1)
to partial
when given <= 2 arguments.
This would be the correct call:
return call_user_func(
partial,
concat_with,
...func_get_args()
);
This needs a test.
So, this is a really cool issue. If we get the reduce example:
$sum = f\reduce('f\add', 0, $numbers); // 90
this will explode:
PHP Warning: array_reduce() expects parameter 2 to be a valid callback, function 'f\add' not found or invalid function name in /home/worms/Documents/phpplayground/vendor/grrr-amsterdam/garp-functional/library/Garp/Functional/Reduce.php on line 21
and that happens because PHP doesn't translate 'f' inside the string to 'Garp\Functional'. You either have to send the whole namespace:
$sum = f\reduce('Garp\Functional\add', 0, $numbers); // 90
Or do a nifty ugly little workaround like I did:
$f = 'Garp\Functional\\';
$sum = f\reduce($f.'add', 0, $numbers); // 90
So this opens up 2 issues:
(Solved in PR: #5) We need to fix the docs example because it doesn't work and may cause confusion.
Is there a better way to send functions inside renamed namespaces as parameters?
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.