Last active
September 11, 2019 15:24
-
-
Save alldne/eef488da59b4e7e4bbe1414ee8e3738c to your computer and use it in GitHub Desktop.
[RxCocoa] Use `bind(to:)` on an array of `ObserverType`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array: ObserverType where Element: ObserverType { | |
public typealias E = Element.E | |
public func on(_ event: Event<E>) { | |
forEach { (element) in | |
element.on(event) | |
} | |
} | |
} | |
extension Array where Element: ObserverType { | |
func asObserver() -> AnyObserver<Element.Element> { | |
return AnyObserver<Element.Element>(eventHandler: { (event) in | |
self.forEach { (element) in | |
element.on(event) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment