Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partitionBy to split into arbitrary amounts of partitions #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add partitionBy to split into arbitrary amounts of partitions #18

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 4, 2019

This adds support for partitionBy, to allow partitioning into more than two partitions. This can be useful if you have a list of things that you want to group by (groupBy could be made an alias of this) a specific property or other criteria - the sky is the limit with callback functions 馃槂.

partitionBy behaves the same as partition if you use a true unary predicate (something that returns a boolean based on the argument), but allows other functions that return different types than booleans.

Currently only int and string return values are allowed, since that's what arrays support as keys, but in the future you could also allow returning Comparable objects or arbitrary objects and use something like SplObjectStorage.

@ghost
Copy link
Author

ghost commented Jul 5, 2019

Thinking more on this, I see partition could also support other callables as well, since the functions are near identical, except for treatment of the callback return value. partitionBy with the same callback as partition will also behave in the same way, that is, if the callback returns a boolean as is intended.

On the other hand, this would be backwards incompatible, since you can now pass callbacks to partition that pass something else than booleans and they will be converted for you; using partitionBy will result in different behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

0 participants