Generate 'chunked' and 'windowed' signatures and delegating implementations
Add implementations of windowed.
This commit is contained in:
@@ -1798,6 +1798,16 @@ public fun <T : Any> List<T?>.requireNoNulls(): List<T> {
|
||||
return this as List<T>
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> Iterable<T>.chunked(size: Int): List<List<T>> {
|
||||
return chunked(size) { it.toList() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T, R> Iterable<T>.chunked(size: Int, transform: (List<T>) -> R): List<R> {
|
||||
return windowed(size, size, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements of the original collection without the first occurrence of the given [element].
|
||||
*/
|
||||
@@ -1986,6 +1996,19 @@ public inline fun <T> Collection<T>.plusElement(element: T): List<T> {
|
||||
return plus(element)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> Iterable<T>.windowed(size: Int, step: Int): List<List<T>> {
|
||||
return windowed(size, step) { it.toList() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T, R> Iterable<T>.windowed(size: Int, step: Int, transform: (List<T>) -> R): List<R> {
|
||||
if (this is List) {
|
||||
return windowIndices(this.size, size, step, dropTrailing = false).asIterable().map { transform(subList(it.start, it.endInclusive + 1)) }
|
||||
}
|
||||
return windowForwardOnlySequenceImpl(iterator(), size, step, dropTrailing = false).asIterable().map(transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
|
||||
*/
|
||||
|
||||
@@ -1331,6 +1331,16 @@ public fun <T : Any> Sequence<T?>.requireNoNulls(): Sequence<T> {
|
||||
return map { it ?: throw IllegalArgumentException("null element found in $this.") }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> Sequence<T>.chunked(size: Int): Sequence<List<T>> {
|
||||
return chunked(size) { it.toList() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T, R> Sequence<T>.chunked(size: Int, transform: (List<T>) -> R): Sequence<R> {
|
||||
return windowed(size, size, transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
|
||||
*
|
||||
@@ -1507,6 +1517,16 @@ public inline fun <T> Sequence<T>.plusElement(element: T): Sequence<T> {
|
||||
return plus(element)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T> Sequence<T>.windowed(size: Int, step: Int): Sequence<List<T>> {
|
||||
return windowed(size, step) { it.toList() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <T, R> Sequence<T>.windowed(size: Int, step: Int, transform: (List<T>) -> R): Sequence<R> {
|
||||
return Sequence { windowForwardOnlySequenceImpl(iterator(), size, step, dropTrailing = false).iterator() }.map(transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence of pairs built from elements of both sequences with same indexes.
|
||||
* Resulting sequence has length of shortest input sequence.
|
||||
|
||||
@@ -1110,6 +1110,26 @@ public inline fun CharSequence.sumByDouble(selector: (Char) -> Double): Double {
|
||||
return sum
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun CharSequence.chunked(size: Int): List<String> {
|
||||
return chunked(size) { it.toString() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <R> CharSequence.chunked(size: Int, transform: (CharSequence) -> R): List<R> {
|
||||
return windowed(size, size, transform)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun CharSequence.chunkedSequence(size: Int): Sequence<String> {
|
||||
return chunkedSequence(size) { it.toString() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <R> CharSequence.chunkedSequence(size: Int, transform: (CharSequence) -> R): Sequence<R> {
|
||||
return windowedSequence(size, size, transform)
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun CharSequence.pairwise(): List<Pair<Char, Char>> {
|
||||
return pairwise { a, b -> a to b }
|
||||
@@ -1162,6 +1182,26 @@ public inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, S
|
||||
return Pair(first.toString(), second.toString())
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun CharSequence.windowed(size: Int, step: Int): List<String> {
|
||||
return windowed(size, step) { it.toString() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <R> CharSequence.windowed(size: Int, step: Int, transform: (CharSequence) -> R): List<R> {
|
||||
return windowIndices(this.length, size, step, dropTrailing = false).asIterable().map { transform(subSequence(it)) }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun CharSequence.windowedSequence(size: Int, step: Int): Sequence<String> {
|
||||
return windowedSequence(size, step) { it.toString() }
|
||||
}
|
||||
|
||||
@SinceKotlin("1.2")
|
||||
public fun <R> CharSequence.windowedSequence(size: Int, step: Int, transform: (CharSequence) -> R): Sequence<R> {
|
||||
return windowIndices(this.length, size, step, dropTrailing = false).map { transform(subSequence(it)) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user