Skip to content

Instantly share code, notes, and snippets.

@nalexn
Last active October 21, 2019 15:16
Show Gist options
  • Save nalexn/10434d48d421a0f62ffecc5c36c3e57c to your computer and use it in GitHub Desktop.
Save nalexn/10434d48d421a0f62ffecc5c36c3e57c to your computer and use it in GitHub Desktop.
class ValueConsumer {
private var subscriptions = Set<AnyCancellable>()
private let mySubject = CurrentValueSubject<Int, Never>(0)
private var myVar: Int = 0
func consumeValues(publisher1, ...) {
subscriptions.collect {
publisher1
.sink { print("New value: \($0)") }
mySubject
.subscribe(publisher2)
publisher3
.assign(to: \.myVar, on: self)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment