Collections API
There are a number of extension functions on Collection, Iterator, Map and arrays to allow easy composition collections using familiar combinators like
Functions on Collection, Map and arrays are all eager, in that methods like map() will create a complete result List when the method completes.
Functions on Iterator are lazy so that they try to return new iterators that lazily evaluate things. For example map() returns a new Iterator that lazily maps the values in the original iterator.
Preconditions
When writing code it is recommended you add checks early in a function to ensure parameters are valid. There are a number of helper methods for this:
- assert(Boolean) and assert(Boolean) { lazyMessage } which use the JDK's assertion feature so they can be disabled using the -ea option
- check(Boolean) and check(Boolean) { lazyMessage } for checking something to be true and throwing IllegalStateException if not
- require(Boolean) and require(Boolean) { lazyMessage } for requiring something to be true and throwing IllegalArgumentException if not