Introduce new overloads of flatMap and flatMapTo

- Sequence<T>.flatMap((T) -> Iterable<R>)
- Iterable<T>.flatMap((T) -> Sequence<R>)
- Array<T>.flatMap((T) -> Sequence<R>)
- Map.flatMap((Entry) -> Sequence<R>)

KT-34506
This commit is contained in:
Ilya Gorbunov
2020-04-24 05:15:07 +03:00
parent 562788ceb9
commit bdd53ee9cd
10 changed files with 233 additions and 9 deletions
@@ -46,6 +46,17 @@ class CollectionTest {
assertStaticAndRuntimeTypeIs<List<String>>(foo)
}
@Test fun flatMap() {
val source = listOf(null, "foo", "bar")
val result1 = source.flatMap { it.orEmpty().asSequence() }
val result2 = source.flatMap { it.orEmpty().asIterable() }
val expected = "foobar".toList()
assertEquals(expected, result1)
assertEquals(expected, result2)
}
/*
@Test fun mapNotNull() {
val data = listOf(null, "foo", null, "bar")