Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save skywalkerlw/19d7f250659f14ce61ac195b610a39eb to your computer and use it in GitHub Desktop.
Save skywalkerlw/19d7f250659f14ce61ac195b610a39eb to your computer and use it in GitHub Desktop.
class Counter {
let publisher = PassthroughSubject<Int, Never>()
private(set) var value = 0 {
didSet {
publisher.send(value)
}
}
func increment() {
value += 1
}
}
let counter = Counter()
let cancellable = counter.publisher
.filter { $0 > 2}
.sink { value in
print(value)
}
counter.increment()
counter.increment()
counter.increment()
counter.increment()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment