Skip to content

Commit

Permalink
🎨 Remove map operator #122
Browse files Browse the repository at this point in the history
  • Loading branch information
YutoMizutani committed Nov 26, 2018
1 parent b4776f6 commit 7043159
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Sources/Application/Extensions/ObservableType+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ public extension ObservableType {
}

func store(startWith: Self.E) -> Observable<(newValue: E, oldValue: E)> {
return Observable.zip(self, self.startWith(startWith)).map { (newValue: $0.0, oldValue: $0.1) }
return Observable.zip(self, self.startWith(startWith)) { a, b in
(newValue: a, oldValue: b)
}
}

func store() -> Observable<(newValue: E, oldValue: E?)> {
return Observable.zip(self, self.map(Optional.init).startWith(nil)).map { (newValue: $0.0, oldValue: $0.1) }
return Observable.zip(self, self.map(Optional.init).startWith(nil)) { a, b in
(newValue: a, oldValue: b)
}
}
}

public extension ObservableType {
/// Count up
func count() -> Observable<Int> {
return reduce(0) { n, _ in n + 1 }
return flatMap { _ in self.reduce(0) { n, _ in n + 1 } }
}

/// Get time
Expand All @@ -43,7 +47,10 @@ public extension ObservableType {

/// Response entity
func response(_ timer: TimerUseCase) -> Observable<ResponseEntity> {
return Observable.zip(count(), getTime(timer))
.map { ResponseEntity($0.0, $0.1) }
return flatMap { _ in
return Observable.zip(self.count(), self.getTime(timer)) { a, b in
ResponseEntity(a, b)
}
}
}
}

0 comments on commit 7043159

Please sign in to comment.