Add tests for windowed and chunked, fix precondition checks

This commit is contained in:
Ilya Gorbunov
2017-05-04 11:03:00 +03:00
parent a3a1c391cc
commit 18c7a01ab5
7 changed files with 204 additions and 5 deletions
@@ -1502,6 +1502,7 @@ public fun <T> Sequence<T>.windowed(size: Int, step: Int): Sequence<List<T>> {
@SinceKotlin("1.2")
public fun <T, R> Sequence<T>.windowed(size: Int, step: Int, transform: (List<T>) -> R): Sequence<R> {
require(size > 0 && step > 0) { "size $size and step $step both must be greater than zero" }
return Sequence { windowForwardOnlySequenceImpl(iterator(), size, step, dropTrailing = false).iterator() }.map(transform)
}