Nice to meet you! I'm Setaro during RxSwift warrior training with Tupple.
This is a memorandum and memo of the method chain that I have learned since I started writing RxSwift.
By writing a combination of methods, I am programming with a method to avoid the side effects of functional programming, and I am writing more readable and declarative code. In order to realize declarative coding, the description of the process by the method chain is basic and important.
//Double the entered Int type value
_ = Observable.just(10)
.map { $0 * 2 }
.subscribe(onNext: { print($0) // => 20
})
As long as the type is the same, you can connect processing such as .map for the rest of your life, In this case, if you subscribe, the type will change, so dispose Bag and exit.
(Maybe people who write this in a connected way say "relatively declarative writing")
And if you change the return value of the closure of map to Int → String Events that can be subscribed are also Int → String. ** The type that can be subscribed to depends on the return value of the closure used in the map **
RxSwift operators implement method chains by defining interfaces that use generics.
Recommended Posts