Skip to content

Instantly share code, notes, and snippets.

@maximn
Last active February 22, 2018 20:53
Show Gist options
  • Save maximn/9a56347c93eda5c508c0 to your computer and use it in GitHub Desktop.
Save maximn/9a56347c93eda5c508c0 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