don't generate two 'flatMap' methods(*) for Iterator
* with the same erased signature #KT-3373 Fixed
This commit is contained in:
@@ -35,6 +35,13 @@ public inline fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {
|
||||
return mapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <T, R> Collection<T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing the first *n* elements
|
||||
*/
|
||||
|
||||
@@ -90,13 +90,6 @@ public inline fun <T, R, C: MutableCollection<in R>> Iterable<T>.mapTo(result: C
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <T, R> Iterable<T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
|
||||
@@ -90,13 +90,6 @@ public inline fun <T, R, C: MutableCollection<in R>> Iterator<T>.mapTo(result: C
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single list
|
||||
*/
|
||||
public inline fun <T, R> Iterator<T>.flatMap(transform: (T)-> Iterable<R>) : List<R> {
|
||||
return flatMapTo(ArrayList<R>(), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of transforming each element to one or more values which are concatenated together into a single collection
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,7 @@ class IteratorsJVMTest {
|
||||
iterate<Char> { if (index < binary.length()) binary.get(index++) else null }
|
||||
}
|
||||
|
||||
val expected = arrayList(
|
||||
val expected = arrayListOf(
|
||||
'0', // fibonacci(0) = 0
|
||||
'1', // fibonacci(1) = 1
|
||||
'1', // fibonacci(2) = 1
|
||||
@@ -25,4 +25,9 @@ class IteratorsJVMTest {
|
||||
|
||||
assertEquals(expected, fibonacci().flatMap<Int, Char>(intToBinaryDigits()).take(10).toList())
|
||||
}
|
||||
|
||||
test fun flatMapOnIterator() {
|
||||
val result = listOf(1, 2).iterator().flatMap { i -> (0..i).iterator()}
|
||||
assertEquals(listOf(0, 1, 0, 1, 2), result.toList())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user