Skip to content

Instantly share code, notes, and snippets.

@liango2
Forked from maximn/assert
Created December 30, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liango2/9eba6502b8bdd73dd975 to your computer and use it in GitHub Desktop.
Save liango2/9eba6502b8bdd73dd975 to your computer and use it in GitHub Desktop.
Scala preconditions
val rnd = Math.random()
val n = Math.abs(rnd)
assert(n > 0)
val speedFromSensor: Double = ...
assume(speedFromSensor >= 0)
def doublePositive(n: Int): Int = {
require(n > 0)
n * 2 // logic
} ensuring(n => n >= 0 && n % 2 == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment