Skip to content

Commit edb1be6

Browse files
committed
ImmutableList.Builder.subList should return a view of the builder.
1 parent c01f6b6 commit edb1be6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/ImmutableVectorList.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ internal class ImmutableVectorList<out E> private constructor(private val impl:
111111

112112
override fun set(index: Int, element: E): E = get(index).apply { mutate { it.with(index, element) } }
113113

114-
// TODO: make subList a view of this builder, rather than builder of the view
115-
override fun subList(fromIndex: Int, toIndex: Int): Builder<E> = Builder(value, impl.subList(fromIndex, toIndex))
114+
// to make subList a view of this builder, rather than builder of the view
115+
//override fun subList(fromIndex: Int, toIndex: Int): Builder<E> = Builder(value, impl.subList(fromIndex, toIndex))
116116
}
117117

118118
}

kotlinx-collections-immutable/tests/src/test/kotlin/kotlinx.collections.immutable/ImmutableListTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ class ImmutableListTest {
118118
}
119119
}
120120

121+
@Test fun subListOfBuilder() {
122+
val list = "abcxaxyz12".toImmutableList()
123+
val builder = list.builder()
124+
val subList = builder.subList(2, 5)
125+
builder[4] = 'b'
126+
assertEquals("cxb", subList.joinToString(""))
127+
subList.replaceAll { it -> it + 1 }
128+
assertEquals("abdycxyz12", builder.joinToString(""))
129+
}
130+
121131
fun <T> ImmutableList<T>.testMutation(operation: MutableList<T>.() -> Unit) {
122132
val mutable = this.toMutableList()
123133
val builder = this.builder()

0 commit comments

Comments
 (0)