Skip to content

Instantly share code, notes, and snippets.

@maximn maximn/assert
Last active Feb 22, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.