Skip to content

Commit

Permalink
back to non optional flatMapLatest
Browse files Browse the repository at this point in the history
  • Loading branch information
psharanda committed Sep 21, 2017
1 parent ebbe2d6 commit 1a1295f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Sources/Observable+FlatMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import Foundation

extension ObservableProtocol {

public func flatMapLatest<U>(_ f: @escaping ((ValueType) -> Observable<U>?)) -> Observable<U> {
public func flatMapLatest<U>(_ f: @escaping ((ValueType) -> Observable<U>)) -> Observable<U> {
return Observable<U> { observer in
let serial = SwapableDisposable()
serial.swap(parent: self.subscribe { result in
serial.disposeChild()
serial.swap(child: f(result)?.subscribe(observer))
serial.swap(child: f(result).subscribe(observer))
})
return serial
}
}

public func flatMapMerge<U>(_ f: @escaping ((ValueType) -> Observable<U>?)) -> Observable<U> {
public func flatMapMerge<U>(_ f: @escaping ((ValueType) -> Observable<U>)) -> Observable<U> {
return Observable<U> { observer in
let multi = MultiDisposable()

multi.add(self.subscribe { result in
multi.add(f(result)?.subscribe(observer))
multi.add(f(result).subscribe(observer))
})
return multi
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Observable+Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension ObservableProtocol where ValueType: ResultConvertible {

public typealias ResultValueType = ValueType.ValueType

public func flatMapLatestValue<U>(_ f: @escaping (ResultValueType)->Task<U>?) -> Task<U> {
public func flatMapLatestValue<U>(_ f: @escaping (ResultValueType)->Task<U>) -> Task<U> {
return flatMapLatest { result in
switch result.result {
case .success(let value):
Expand All @@ -20,7 +20,7 @@ extension ObservableProtocol where ValueType: ResultConvertible {
}
}

public func flatMapMergeValue<U>(_ f: @escaping (ResultValueType)->Task<U>?) -> Task<U> {
public func flatMapMergeValue<U>(_ f: @escaping (ResultValueType)->Task<U>) -> Task<U> {
return flatMapMerge { result in
switch result.result {
case .success(let value):
Expand Down

0 comments on commit 1a1295f

Please sign in to comment.