Skip to content

Commit 300923e

Browse files
M0rtyMerrfreak4pc
authored andcommitted
Fix filterMap doc and use compactMap internally (#231)
1 parent b262ddd commit 300923e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ let resilientRequest = request.apply(requestPolicy)
454454
A common pattern in Rx is to filter out some values, then map the remaining ones to something else. `filterMap` allows you to do this in one step:
455455

456456
```swift
457-
// keep only odd numbers and double them
457+
// keep only even numbers and double them
458458
Observable.of(1,2,3,4,5,6)
459459
.filterMap { number in
460460
(number % 2 == 0) ? .ignore : .map(number * 2)

Source/RxSwift/filterMap.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ extension ObservableType {
2323
- returning `.map(newValue)` will propagate newValue through the returned Observable.
2424
*/
2525
public func filterMap<Result>(_ transform: @escaping (Element) throws -> FilterMap<Result>) -> Observable<Result> {
26-
return flatMap { element -> Observable<Result> in
26+
return compactMap { element in
2727
switch try transform(element) {
2828
case .ignore:
29-
return .empty()
29+
return nil
3030
case let .map(result):
31-
return .just(result)
31+
return result
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)