This repository has been archived by the owner on Oct 25, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[General] Added collection shortcuts for Observable.
- Loading branch information
1 parent
c8f156c
commit e2f119b
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// Collection+Shortcuts.swift | ||
// RxShortcuts | ||
// | ||
// Created by sunshinejr on 25.11.2016. | ||
// Copyright (c) 2016 sunshinejr. All rights reserved. | ||
// | ||
|
||
import RxSwift | ||
|
||
public extension Collection where Iterator.Element: ObservableType { | ||
|
||
/** | ||
Merges elements from all observable sequences in the given enumerable sequence into a single observable sequence. | ||
- seealso: [merge operator on reactivex.io](http://reactivex.io/documentation/operators/merge.html) | ||
- returns: The observable sequence that merges the elements of the observable sequences. | ||
*/ | ||
func merge() -> Observable<Self.Iterator.Element.E> { | ||
return Observable.from(self).merge() | ||
} | ||
|
||
/** | ||
Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element. | ||
- seealso: [combineLatest operator on reactivex.io](http://reactivex.io/documentation/operators/combinelatest.html) | ||
- parameter resultSelector: Function to invoke whenever any of the sources produces an element. | ||
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function. | ||
*/ | ||
func combineLatest<T>(resultSelector: @escaping ([Self.Iterator.Element.E]) throws -> T) -> Observable<T> { | ||
return Observable.combineLatest(self, resultSelector) | ||
} | ||
|
||
/** | ||
Merges the specified observable sequences into one observable sequence by using the selector function whenever all of the observable sequences have produced an element at a corresponding index. | ||
- seealso: [zip operator on reactivex.io](http://reactivex.io/documentation/operators/zip.html) | ||
- parameter resultSelector: Function to invoke for each series of elements at corresponding indexes in the sources. | ||
- returns: An observable sequence containing the result of combining elements of the sources using the specified result selector function. | ||
*/ | ||
func zip<T>(resultSelector: @escaping ([Self.Iterator.Element.E]) throws -> T) -> Observable<T> { | ||
return Observable.zip(self, resultSelector) | ||
} | ||
|
||
/** | ||
Concatenates all inner observable sequences, as long as the previous observable sequence terminated successfully. | ||
- seealso: [concat operator on reactivex.io](http://reactivex.io/documentation/operators/concat.html) | ||
- returns: An observable sequence that contains the elements of each observed inner sequence, in sequential order. | ||
*/ | ||
func concat() -> Observable<Self.Iterator.Element.E> { | ||
return Observable.from(self).concat() | ||
} | ||
} |