Preconditions are useful, especially in a dynamically-typed language.
require
can check for a boolean expression along with an error message. In case of error, it
throws an AssertionError
.
function foo = |a| { require(a oftype String.class, "a must be a String") ... }
You may also use requireNotNull
that… well… checks that its argument is not null
:
function foo = |a| { requireNotNull(a) ... }