0

Sorry nooby kotlin question

func someThingElse(): Observable<String> {
   return Observable.just("aasd")
} 

fun doSomething(): Observable<Void> {
    return someThisElse().fetch().map { () } 
}

How do i return an observable of void? I tried void, Void(), Void

aryaxt
  • 76,198
  • 92
  • 293
  • 442

2 Answers2

3

Equivalent of Observable<Void> i.e. Observable that doesn't return any value - only completes or ends with exception - is Completable:

Represents a deferred computation without any value but only indication for completion or exception.

michalbrz
  • 3,354
  • 1
  • 30
  • 41
  • 2
    Just an addition: You can use `ignoreElements` to convert an Observable to a Completable: https://stackoverflow.com/questions/40399397/how-to-convert-rxjava2s-observable-to-completable – Christopher Jun 20 '18 at 09:43
  • 1
    `Observable` does return value of unit type (void) via 0...N `next` events, so it is definitely not equivalent to `Completable`, which does not produce `next` events. – Sergiy Salyuk Nov 13 '20 at 08:45
2

Unit in Kotlin corresponds to void in Java. Like void, Unit is the default return type of any function in Kotlin that does return anything.

Using Completable, Single or Maybe might make more sense though

Mostafa Gazar
  • 2,487
  • 18
  • 23