Provide flatMapIndexed operation
- similar to flatMap, but transform function takes index and element #KT-36894
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -1242,6 +1242,11 @@ class StringTest {
|
||||
assertEquals("a ab abc abcd ".toList(), result)
|
||||
}
|
||||
|
||||
@Test fun flatMapIndexed() = withOneCharSequenceArg("bdfi") { data ->
|
||||
val result = data.flatMapIndexed { index, c -> ('a'..c).drop(index) + ' ' }
|
||||
assertEquals("ab bcd cdef defghi ".toList(), result)
|
||||
}
|
||||
|
||||
@Test fun fold() = withOneCharSequenceArg { arg1 ->
|
||||
// calculate number of digits in the string
|
||||
val data = arg1("a1b2c3def")
|
||||
|
||||
Reference in New Issue
Block a user