Merge branch 'develop' of github.com:kzaher/RxSwift into develop

This commit is contained in:
Krunoslav Zaher 2015-06-05 12:53:21 +02:00
commit 5700fdbd15
2 changed files with 32 additions and 0 deletions

View File

@ -101,6 +101,27 @@ example("returnElements") {
With the above, you will see that the `.Next` event was sent ten times, once for each element. Then `.Complete` was sent.
*/
/*:
### from
We can also create an observable from any SequenceType, such as an array
*/
example("from") {
let fromArrayObservable = from([1, 2, 3, 4, 5])
let fromArrayObservableSubscriber = fromArrayObservable
>- subscribe { event in
switch event {
case .Next(let box):
println("\(box.value)")
case .Completed:
println("completed")
case .Error(let error):
println("\(error)")
}
}
}
/*:
Now these functions are all well and good, but the really useful ones are in the RxCocoa library.
`rx_observe` exist on every NSObject and wraps KVO.

View File

@ -56,6 +56,17 @@ public func returnElements<E>(values: E ...) -> Observable<E> {
}
}
public func from<E, S where S: SequenceType, S.Generator.Element == E>(sequence: S) -> Observable<E> {
return AnonymousObservable { observer in
for element in sequence {
sendNext(observer, element)
}
sendCompleted(observer)
return DefaultDisposable()
}
}
// fail
public func failWith<E>(error: ErrorType) -> Observable<E> {