Rename Stream<T> to Sequence<T> and provide migration path via deprecated types and functions.
This commit is contained in:
@@ -10,7 +10,7 @@ class FunctionIteratorTest {
|
||||
Test fun iterateOverFunction() {
|
||||
var count = 3
|
||||
|
||||
val iter = stream<Int> {
|
||||
val iter = sequence<Int> {
|
||||
count--
|
||||
if (count >= 0) count else null
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class FunctionIteratorTest {
|
||||
}
|
||||
|
||||
Test fun iterateOverFunction2() {
|
||||
val values = stream<Int>(3) { n -> if (n > 0) n - 1 else null }
|
||||
val values = sequence<Int>(3) { n -> if (n > 0) n - 1 else null }
|
||||
assertEquals(arrayListOf(3, 2, 1, 0), values.toList())
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class IteratorsJVMTest {
|
||||
fun intToBinaryDigits() = { (i: Int) ->
|
||||
val binary = Integer.toBinaryString(i)!!
|
||||
var index = 0
|
||||
stream<Char> { if (index < binary.length()) binary.get(index++) else null }
|
||||
sequence<Char> { if (index < binary.length()) binary.get(index++) else null }
|
||||
}
|
||||
|
||||
val expected = arrayListOf(
|
||||
@@ -27,7 +27,7 @@ class IteratorsJVMTest {
|
||||
}
|
||||
|
||||
test fun flatMapOnIterator() {
|
||||
val result = streamOf(1, 2).flatMap { i -> (0..i).stream()}
|
||||
val result = sequenceOf(1, 2).flatMap { i -> (0..i).sequence()}
|
||||
assertEquals(listOf(0, 1, 0, 1, 2), result.toList())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import org.junit.Test as test
|
||||
import kotlin.test.fails
|
||||
import java.util.ArrayList
|
||||
|
||||
fun fibonacci(): Stream<Int> {
|
||||
fun fibonacci(): Sequence<Int> {
|
||||
// fibonacci terms
|
||||
var index = 0; var a = 0; var b = 1
|
||||
return stream<Int> { when (index++) { 0 -> a; 1 -> b; else -> { val result = a + b; a = b; b = result; result } } }
|
||||
return sequence<Int> { when (index++) { 0 -> a; 1 -> b; else -> { val result = a + b; a = b; b = result; result } } }
|
||||
}
|
||||
|
||||
class IteratorsTest {
|
||||
@@ -39,12 +39,12 @@ class IteratorsTest {
|
||||
}
|
||||
|
||||
test fun plus() {
|
||||
val iter = arrayListOf("foo", "bar").stream()
|
||||
val iter = arrayListOf("foo", "bar").sequence()
|
||||
val iter2 = iter + "cheese"
|
||||
assertEquals(arrayListOf("foo", "bar", "cheese"), iter2.toList())
|
||||
|
||||
// lets use a mutable variable
|
||||
var mi = streamOf("a", "b")
|
||||
var mi = sequenceOf("a", "b")
|
||||
mi += "c"
|
||||
assertEquals(arrayListOf("a", "b", "c"), mi.toList())
|
||||
}
|
||||
@@ -52,12 +52,12 @@ class IteratorsTest {
|
||||
test fun plusCollection() {
|
||||
val a = arrayListOf("foo", "bar")
|
||||
val b = arrayListOf("cheese", "wine")
|
||||
val iter = a.stream() + b.stream()
|
||||
val iter = a.sequence() + b.sequence()
|
||||
assertEquals(arrayListOf("foo", "bar", "cheese", "wine"), iter.toList())
|
||||
|
||||
// lets use a mutable variable
|
||||
var ml = arrayListOf("a").stream()
|
||||
ml += a.stream()
|
||||
var ml = arrayListOf("a").sequence()
|
||||
ml += a.sequence()
|
||||
ml += "beer"
|
||||
ml += b
|
||||
ml += "z"
|
||||
@@ -65,11 +65,11 @@ class IteratorsTest {
|
||||
}
|
||||
|
||||
test fun requireNoNulls() {
|
||||
val iter = arrayListOf<String?>("foo", "bar").stream()
|
||||
val iter = arrayListOf<String?>("foo", "bar").sequence()
|
||||
val notNull = iter.requireNoNulls()
|
||||
assertEquals(arrayListOf("foo", "bar"), notNull.toList())
|
||||
|
||||
val iterWithNulls = arrayListOf("foo", null, "bar").stream()
|
||||
val iterWithNulls = arrayListOf("foo", null, "bar").sequence()
|
||||
val notNull2 = iterWithNulls.requireNoNulls()
|
||||
fails {
|
||||
// should throw an exception as we have a null
|
||||
|
||||
Reference in New Issue
Block a user