Skip to content

Instantly share code, notes, and snippets.

@alldne
Last active September 11, 2019 15:24
Show Gist options
  • Save alldne/eef488da59b4e7e4bbe1414ee8e3738c to your computer and use it in GitHub Desktop.
Save alldne/eef488da59b4e7e4bbe1414ee8e3738c to your computer and use it in GitHub Desktop.
[RxCocoa] Use `bind(to:)` on an array of `ObserverType`
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