Is there a preferred type for an Observable with no need for a value in Next events?
You can simply use an Observable<Void>
for this purpose. Like so:
let triggerObservable = Observable<Void>.just()
triggerObservable.subscribeNext() {
debugPrint("received notification!")
}.addDisposableTo(disposeBag)
or in your example:
let triggeringObservable: Observable<Void>
// ...
triggeringObservable.map { Void -> String in // The actual value is ignored
return SomeLibrary.username()
}
In Swift 4 (and probably earlier) you can pass an empty tuple as an argument to a method expecting a Void associated type.
var triggerObservable = PublishSubject<Void>()
...
triggerObservable.onNext(()) // "()" empty tuple is accepted for a Void argument
Or you can define an extension to overload onNext() with no args for the Void case:
extension ObserverType where E == Void {
public func onNext() {
onNext(())
}
}
...
triggerObservable.onNext()
This worked for me on Swift 4.1:
Observable<Void>.just(Void())