Writing custom generators for ScalaCheck can be one of the more difficult and/or time-consuming parts of using it. As a result I thought I’d start putting together a list of generators that I have written or seen elsewhere. Unfortunately I can’t credit all the ones I’ve seen in other places because I google’d and copied them many moons ago, but I’ll give credit/attribution to all the ones I can.Back to top
This is a combination of generators I wrote, and some that I copied from other places and may have modified a little:
Important note about Seq, IndexedSeq, and LinearSeq
As an important note, I use
Seq in the following examples to keep things simple, but in your code you should be more precise and use
LinearSeq where appropriate. As the
Seq class Scaladoc states:
PayPal Engineering has an article titled, Learning from Using a Reactive Platform — Akka/Squbs.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.3, “How to read and write binary files in Scala.”
You want to read data from a binary file or write data to a binary file.
Scala doesn’t offer any special conveniences for reading or writing binary files, so use the Java
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.6, “How to Use the Scala Stream Class, a Lazy Version of a List”
You want to use a collection that works like a
List but invokes its transformer methods (
filter, etc.) lazily.