diff --git a/libraries/stdlib/src/kotlin/ReadMe.md b/libraries/stdlib/src/kotlin/ReadMe.md new file mode 100644 index 00000000000..4d853bbae74 --- /dev/null +++ b/libraries/stdlib/src/kotlin/ReadMe.md @@ -0,0 +1,20 @@ +## Collections API + +There are a number of extension functions on [Collection](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/java/util/Collection-extensions.html), [Iterator](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/java/util/Iterator-extensions.html), [Map](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/java/util/Map-extensions.html) and arrays to allow easy composition collections using familiar combinators like + +* filter() +* flatMap() +* map() +* fold() + +Functions on [Collection](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/java/util/Collection-extensions.html), [Map](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/java/util/Map-extensions.html) and arrays are all *eager*, in that methods like map() will create a complete result List when the method completes. + +Functions on [Iterator](http://jetbrains.github.com/kotlin/versions/snapshot/apidocs/kotlin/java/util/Iterator-extensions.html) 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](http://docs.oracle.com/javase/6/docs/api/java/lang/IllegalStateException.html) if not +* require(Boolean) and require(Boolean) { lazyMessage } for requiring something to be true and throwing [IllegalArgumentException](http://docs.oracle.com/javase/6/docs/api/java/lang/IllegalArgumentException.html) if not