GroupedObservable.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // GroupedObservable.swift
  3. // RxSwift
  4. //
  5. // Created by Tomi Koskinen on 01/12/15.
  6. // Copyright © 2015 Krunoslav Zaher. All rights reserved.
  7. //
  8. /// Represents an observable sequence of elements that have a common key.
  9. public struct GroupedObservable<Key, Element> : ObservableType {
  10. /// Gets the common key.
  11. public let key: Key
  12. private let source: Observable<Element>
  13. /// Initializes grouped observable sequence with key and source observable sequence.
  14. ///
  15. /// - parameter key: Grouped observable sequence key
  16. /// - parameter source: Observable sequence that represents sequence of elements for the key
  17. /// - returns: Grouped observable sequence of elements for the specific key
  18. public init(key: Key, source: Observable<Element>) {
  19. self.key = key
  20. self.source = source
  21. }
  22. /// Subscribes `observer` to receive events for this sequence.
  23. public func subscribe<Observer: ObserverType>(_ observer: Observer) -> Disposable where Observer.Element == Element {
  24. return self.source.subscribe(observer)
  25. }
  26. /// Converts `self` to `Observable` sequence.
  27. public func asObservable() -> Observable<Element> {
  28. return self.source
  29. }
  30. }