Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ioleo
Copy link
Member

@ioleo ioleo commented Jul 15, 2019

The zio.random.Random is missing shuffle method, probably due to implicit argument in scala.util.Random.shuffle interface (AFAIK ZIO is implicit-free by design).

Neverthless having a shuffle method for some basic types like: Array or List would be really nice.

@ioleo ioleo changed the title Add Random.shuffle method - solves #1183 Add Random.shuffle method Jul 15, 2019
@ioleo ioleo mentioned this pull request Jul 15, 2019
@ioleo ioleo force-pushed the patch-2 branch 2 times, most recently from ae29a61 to fe68f3e Compare July 15, 2019 16:17
@ioleo
Copy link
Member Author

ioleo commented Jul 15, 2019

I guess for other types like Array we can convert to/from list and reuse this implementation.

@ioleo ioleo force-pushed the patch-2 branch 5 times, most recently from bc53aa6 to 8f58145 Compare July 15, 2019 19:18
Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful to me! Can you add a few tests? Thank you! 🙏

@ioleo
Copy link
Member Author

ioleo commented Jul 16, 2019

@jdegoes In general for lists.length > 1 there is always a chance the shuffle will yield a list in the same order. Here I test the simplest of scenarios, where the nextInt always returns the same index as the one being swapped with, but obviously there are many ways that can form a "ring" and end up with the same list.

And obviously there are even more combinations which yield a list in diffrent order. Here I chose to only check a "reversed order" scenario.

@jdegoes
Copy link
Member

jdegoes commented Jul 16, 2019

@ioleo Looks great! Thanks for this contribution, and congratulations on your first ZIO contribution!

giphy

@jdegoes jdegoes merged commit 42c25d2 into zio:master Jul 16, 2019
@ioleo ioleo deleted the patch-2 branch July 16, 2019 14:26
ghostdogpr pushed a commit to ghostdogpr/scalaz-zio that referenced this pull request Jul 26, 2019
* Add Random.shuffle method

* Add shuffle testcase
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.

2 participants