-
-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] TODOs for version 2.0 #141
Comments
Suggestion: curry all functions by default (#136) and leave the data for the last argument (much like ramda, they really did get that right) Also, for the |
A So you could do: > ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"].map(unary(parseInt))
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] See: https://lodash.com/docs/4.17.4#unary and http://ramdajs.com/docs/#unary |
@MarcoWorms we had a couple of requests for auto-currying (#136, #41, #118) but my stance is that I canβt think of a way to do this efficiently. This is why I am not considering this for 2.0 right now. @jdreesen indeed it can be worked around but itβs just not a proper map as found in most functional languages. Even PHPs own |
We've talked about this before but one of the pitfalls I keep stepping into is that when you |
@lstrojny What about lazy evaluation? Is that planned? |
@tPl0ch I have no vision around that for now. Do you have an idea on how to do that? |
I personally like the idea of just passing the value into the function for e.g. Removing the collection parameter can be worked around as: map($list, function ($item) use ($list) { /* do something with $list */ }); It's not the most elegant solution, but it works and call attention to the fact that maybe this isn't really the right way to do it. The index can be handled with something like: map(
zip(array_keys($list), array_values($list)),
function ($spot) { list($index, $value) = $item; /* ... */ }
); Then you could use idea of |
I don't know if I like the idea of changing parameter order. To me personally, the order seems correct. It's closest to I want to say I would say generators are a Good Thingβ’. The biggest problem I have with them is being able to reuse the source. As an example, there's no way to rewind the result set from the MySQL flavor of PDO (unlike the Finally, +1 to typehinting as much as possible. Despite the fact I'm stuck on PHP 5.6. BTW, kudos on the great package...I've been using it for quite some time. |
@redbeardcreator on readability: I would love to read it as "map foo over items" but I am not yet sure what the economics of such a change would be. My hunch is, that I want to provide some sort of conversion tool to support the migration. Already out of plain self-interest as we use it quite a bit at @InterNations. |
@lstrojny, a conversion tool would help a lot. Would you want to create one from scratch or do something like a fixing sniff for PHP_CodeSniffer? |
@redbeardcreator I havenβt thought about it a lot yet but I probably need something like https://github.com/Roave/BetterReflection to safely convert e.g. |
@lstrojny regarding auto currying, how hard would it be to just maintain curried versions of certain functions in a separate namespace under `use function Functional{map, curried\map}; |
@ragboyjr hard to tell but I guess they could be generated so it might work |
@lstrojny , check out what Iβve done with krakphp/fn. I auto generate curried versions of functions. |
Have you considered adding function name constants like ihor/nspl has? They are very handy when passing the library functions around. |
@igneus we have |
I must admit I haven't noticed the use Functional as f; // single import statement
f\map(/*...*/); // direct invocation
$myHigherOrderFunction(f\map); // passing reference around |
This was also done in krak/fn library: https://github.com/krakphp/fn The constants there are auto generated which make it very easy to keep in sync. |
I've just sent my proposal for a Pipe in order to get this functionality ;-) long before 2.0 :-)
|
Mission
β Dangerous
π Easy
Topics
β Fix order of
compose
arguments ([IHNFIWIWD] The compose function is executed left to rightΒ #117)compose_2
that fixes the argument ordercompose
and ask people to migrate tocompose_2
pipe
that does whatcompose
does in 1.xcompose
tocompose
compose_2
and ask users to usecompose
insteadFully fledged PHP 7.1 support
iterable
orarray
for container return values?β Do we want to continue passing
value, index, collection
?map
suffers from the same problems JavaScriptβsmap
suffers fromcollection, function
tofunction, collection
The text was updated successfully, but these errors were encountered: