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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Additional collection functions - shuffle(), randomItems() #277

Closed
InverseFalcon opened this issue Feb 11, 2017 · 5 comments

Comments

@InverseFalcon
Copy link
Collaborator

InverseFalcon commented Feb 11, 2017

This requests some additional collection helper functions:

  • shuffle() - shuffles the elements of a given collection
  • randomItem() - returns a random element from the given collection
  • randomItems() - given an integer n, returns a collection of n random elements from the original collection. "removeOnPick" boolean parameter determines if a selection removes it from the list (makes it not available for picking again) or leaves the list alone (so the same item may be randomly picked again.
@jexp
Copy link
Member

jexp commented Feb 11, 2017

In Neo4j 3.2. there is reverse for collections.

The other ones are good ideas, also good starting point for a pull request as those are 1:1 mappings to java.util.Collections.* helper functions.

For randomItems it probably makes more sense to have two functions instead of a boolean parameter, although as we have default values now it could just default to removeOnPick=true.

@InverseFalcon InverseFalcon changed the title Feature Request: Additional collection functions - reverse(), shuffle(), randomItems() Feature Request: Additional collection functions - shuffle(), randomItems() Feb 12, 2017
@InverseFalcon
Copy link
Collaborator Author

I think I may be missing something, how do defaults work between apoc procedure calls and their paired methods?

@jexp
Copy link
Member

jexp commented Feb 14, 2017

Since Neo4j 3.1 you can provide a defaultValue attribute on the @name annotation both for functions and procedures. There are a few examples in the 3.1 branch

@InverseFalcon
Copy link
Collaborator Author

Per the recommendation on slack, I was targeting the 3.0 branch. Is it recommended to target 3.1 at this time instead? Or is it good enough to go for 3.0, and then make the boolean have a default value on 3.1, once it gets there?

@InverseFalcon
Copy link
Collaborator Author

Feature request fulfilled with merge of issue #296, this is on the 3.1 branch.

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

No branches or pull requests

2 participants