Skip to content

Instantly share code, notes, and snippets.

@codeflows
Created January 8, 2016 08:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeflows/e72568fd64d923a3ccfc to your computer and use it in GitHub Desktop.
Save codeflows/e72568fd64d923a3ccfc to your computer and use it in GitHub Desktop.
groupBy for RxSwift
extension ObservableType {
func groupBy<G: Equatable>(predicate: E -> G) -> Observable<Observable<E>> {
return distinctUntilChanged(predicate).map { first in
return self.startWith(first).takeWhile { predicate($0) == predicate(first) }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment