Skip to content

Instantly share code, notes, and snippets.

@hoangchungk53qx1
Created March 24, 2023 03:05
Show Gist options
  • Select an option

  • Save hoangchungk53qx1/67d88e713c6de6a81c99924b86fe940f to your computer and use it in GitHub Desktop.

Select an option

Save hoangchungk53qx1/67d88e713c6de6a81c99924b86fe940f to your computer and use it in GitHub Desktop.
extension Publisher {
// The flatMapLatest operator behaves much like the standard FlatMap operator, except that whenever
// a new item is emitted by the source Publisher, it will unsubscribe to and stop mirroring the Publisher
// that was generated from the previously-emitted item, and begin only mirroring the current one.
func flatMapLatest<T: Publisher>(_ transform: @escaping (Self.Output) -> T) -> Publishers.SwitchToLatest<T, Publishers.Map<Self, T>> where T.Failure == Self.Failure {
map(transform).switchToLatest()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment