Skip to content

Instantly share code, notes, and snippets.

@guillaumecherel
Created June 11, 2015 10:48
Show Gist options
  • Save guillaumecherel/4f0532a61db73f768242 to your computer and use it in GitHub Desktop.
Save guillaumecherel/4f0532a61db73f768242 to your computer and use it in GitHub Desktop.
ScalaCheck generator for shuffled sequences
def shuffle[T](s: Seq[T], prefix: Seq[T] = Vector()): Gen[Seq[T]] =
if (s.length == 0) Gen.const(prefix.toSeq)
else
Gen.choose(0, s.length - 1)
.flatMap { i => shuffle(s.take(i) ++ s.takeRight(s.length - i - 1), prefix :+ s(i)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment