Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension method toSingle #231

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/kotlin/io/reactivex/rxjava3/kotlin/Singles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ inline fun <T : Any, U : Any, R : Any> Single<T>.zipWith(
@SchedulerSupport(SchedulerSupport.NONE)
fun <T : Any, U : Any> Single<T>.zipWith(other: SingleSource<U>): Single<Pair<T, U>> =
zipWith(other, BiFunction { t, u -> Pair(t, u) })

@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
fun <T : Any> T.toSingle(): Single<T> = Single.just(this)
20 changes: 17 additions & 3 deletions src/test/kotlin/io/reactivex/rxjava3/kotlin/SingleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import org.mockito.Mockito
import org.mockito.Mockito.verify

class SingleTest : KotlinTests() {
@Test fun testCreate() {

@Test
fun testCreate() {
Single.create<String> { s ->
s.onSuccess("Hello World!")
}.subscribe { result ->
Expand Down Expand Up @@ -45,13 +47,14 @@ class SingleTest : KotlinTests() {
fun testBlockingSubscribeBy() {
Single.just("Alpha")
.blockingSubscribeBy {
a.received(it)
a.received(it)
}
verify(a, Mockito.times(1))
.received("Alpha")
}

@Test fun testConcatAll() {
@Test
fun testConcatAll() {
(0 until 10)
.map { Single.just(it) }
.concatAll()
Expand All @@ -60,4 +63,15 @@ class SingleTest : KotlinTests() {
Assert.assertEquals((0 until 10).toList(), result)
}
}

@Test
fun testSingleJust() {
val data = "Beta"

data.toSingle()
.subscribeBy(onSuccess = a::received)

verify(a, Mockito.times(1))
.received(data)
}
}