Skip to content

Instantly share code, notes, and snippets.

@twittemb
Created January 1, 2018 23:25
Show Gist options
  • Select an option

  • Save twittemb/0183159ef21e81d077d3ec77a6fdff92 to your computer and use it in GitHub Desktop.

Select an option

Save twittemb/0183159ef21e81d077d3ec77a6fdff92 to your computer and use it in GitHub Desktop.
extension ObservableType {
/// Pauses the elements of the source observable sequence based on
/// the latest element from the second observable sequence.
/// Elements are ignored unless the second sequence has most recently
/// emitted `true`.
/// - Parameter pauser: The observable sequence used to pause the source
/// observable sequence.
/// - Returns: The observable sequence which is paused based upon
/// the pauser observable sequence.
public func pausable<P: ObservableType> ( _ pauser: P) -> Observable<E>
where P.E == Bool {
return withLatestFrom(pauser) { element, paused in
(element, paused)
}.filter { _, paused in
paused
}.map { element, _ in
element
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment