Skip to content

Commit 1acb22e

Browse files
committed
remove withIndex() and joinToString()
1 parent 2546e1a commit 1acb22e

File tree

5 files changed

+1
-67
lines changed

5 files changed

+1
-67
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=1.0.0-RC1-SNAPSHOT
1+
version=1.0.0-RC3
22
org.gradle.jvmargs=-Xms256m -Xmx1024m -XX:MaxPermSize=256m

src/main/kotlin/rx/lang/kotlin/observables.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ fun <T : Any> Observable<T?>.requireNoNulls(): Observable<T> = map { it ?: throw
4444
*/
4545
@Suppress("UNCHECKED_CAST") fun <T : Any> Observable<T?>.filterNotNull(): Observable<T> = filter { it != null } as Observable<T>
4646

47-
/**
48-
* Returns Observable that wrap all values into [IndexedValue] and populates corresponding index value.
49-
*/
50-
fun <T> Observable<T>.withIndex(): Observable<IndexedValue<T>> =
51-
zipWith(Observable.range(0, Int.MAX_VALUE)) { value, index -> IndexedValue(index, value) }
5247

5348
/**
5449
* Returns Observable that emits objects from kotlin [Sequence] returned by function you provided by parameter [body] for

src/main/kotlin/rx/lang/kotlin/operators.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,3 @@ fun <T> Observable<Observable<T>>.switchLatest() = switchMap { it }
2020

2121
fun <T> Observable<Observable<T>>.switchOnNext(): Observable<T> = Observable.switchOnNext(this)
2222

23-
24-
/**
25-
* Joins the emissions of a finite `Observable` into a `String`.
26-
*
27-
* @param separator is the dividing character(s) between each element in the concatenated `String`
28-
*
29-
* @param prefix is the preceding `String` before the concatenated elements (optional)
30-
*
31-
* @param postfix is the succeeding `String` after the concatenated elements (optional)
32-
*/
33-
fun <T> Observable<T>.joinToString(separator: String? = null,
34-
prefix: String? = null,
35-
postfix: String? = null
36-
) = withIndex()
37-
.collect( { StringBuilder(prefix ?: "") },
38-
{ builder: StringBuilder, next: IndexedValue<T> -> builder.append(if (next.index == 0) "" else separator ?: "").append(next.value) }
39-
)
40-
.map { it.append(postfix ?: "").toString() }

src/test/kotlin/rx/lang/kotlin/ExtensionTests.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,6 @@ class ExtensionTests : KotlinTests() {
248248
inOrder.verifyNoMoreInteractions()
249249
}
250250

251-
@Test
252-
fun testJoinToString1() {
253-
254-
val result = Observable.range(1,5)
255-
.joinToString(separator = ",")
256-
.toBlocking().first()
257-
258-
assertTrue(result == "1,2,3,4,5")
259-
}
260-
@Test
261-
fun testJoinToString2() {
262-
263-
val result = Observable.range(1,5)
264-
.joinToString(separator = ",", prefix = "(", postfix = ")")
265-
.toBlocking().first()
266-
267-
assertTrue(result == "(1,2,3,4,5)")
268-
}
269-
270251
val funOnSubscribe: (Int, Subscriber<in String>) -> Unit = { counter, subscriber ->
271252
subscriber.onNext("hello_$counter")
272253
subscriber.onCompleted()

src/test/kotlin/rx/lang/kotlin/ObservablesTest.kt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,6 @@ class ObservablesTest {
100100
}
101101
}
102102

103-
@Test fun testWithIndex() {
104-
listOf("a", "b", "c").toObservable().
105-
withIndex().
106-
toList().
107-
forEach {
108-
assertEquals(listOf(IndexedValue(0, "a"), IndexedValue(1, "b"), IndexedValue(2, "c")), it)
109-
}
110-
}
111-
112-
@Test fun `withIndex() shouldn't share index between multiple subscribers`() {
113-
val o = listOf("a", "b", "c").toObservable().withIndex()
114-
115-
val subscriber1 = TestSubscriber<IndexedValue<String>>()
116-
val subscriber2 = TestSubscriber<IndexedValue<String>>()
117-
118-
o.subscribe(subscriber1)
119-
o.subscribe(subscriber2)
120-
121-
subscriber1.awaitTerminalEvent()
122-
subscriber1.assertValues(IndexedValue(0, "a"), IndexedValue(1, "b"), IndexedValue(2, "c"))
123-
124-
subscriber2.awaitTerminalEvent()
125-
subscriber2.assertValues(IndexedValue(0, "a"), IndexedValue(1, "b"), IndexedValue(2, "c"))
126-
}
127103

128104
@Test fun `kotlin sequence should produce expected items and observable be able to handle em`() {
129105
kotlin.sequences.generateSequence(0) { it + 1 }.toObservable().take(3).toList().forEach {

0 commit comments

Comments
 (0)