-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New observer abstraction for future backpressure support and declutte…
…red stack traces (#799) * Subscriber * /Subscriber/Observer/g; Create the `Operators` namespace.
- Loading branch information
Showing
11 changed files
with
222 additions
and
93 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ PlaygroundUtility.remap | |
# SwiftPM | ||
.build | ||
Packages | ||
.swiftpm | ||
|
||
# Carthage | ||
Carthage/Build | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,21 @@ | ||
extension Operators { | ||
internal final class CompactMap<InputValue, OutputValue, Error: Swift.Error>: Observer<InputValue, Error> { | ||
let downstream: Observer<OutputValue, Error> | ||
let transform: (InputValue) -> OutputValue? | ||
|
||
init(downstream: Observer<OutputValue, Error>, transform: @escaping (InputValue) -> OutputValue?) { | ||
self.downstream = downstream | ||
self.transform = transform | ||
} | ||
|
||
override func receive(_ value: InputValue) { | ||
if let output = transform(value) { | ||
downstream.receive(output) | ||
} | ||
} | ||
|
||
override func terminate(_ termination: Termination<Error>) { | ||
downstream.terminate(termination) | ||
} | ||
} | ||
} |
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,21 @@ | ||
extension Operators { | ||
internal final class Filter<Value, Error: Swift.Error>: Observer<Value, Error> { | ||
let downstream: Observer<Value, Error> | ||
let predicate: (Value) -> Bool | ||
|
||
init(downstream: Observer<Value, Error>, predicate: @escaping (Value) -> Bool) { | ||
self.downstream = downstream | ||
self.predicate = predicate | ||
} | ||
|
||
override func receive(_ value: Value) { | ||
if predicate(value) { | ||
downstream.receive(value) | ||
} | ||
} | ||
|
||
override func terminate(_ termination: Termination<Error>) { | ||
downstream.terminate(termination) | ||
} | ||
} | ||
} |
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,19 @@ | ||
extension Operators { | ||
internal final class Map<InputValue, OutputValue, Error: Swift.Error>: Observer<InputValue, Error> { | ||
let downstream: Observer<OutputValue, Error> | ||
let transform: (InputValue) -> OutputValue | ||
|
||
init(downstream: Observer<OutputValue, Error>, transform: @escaping (InputValue) -> OutputValue) { | ||
self.downstream = downstream | ||
self.transform = transform | ||
} | ||
|
||
override func receive(_ value: InputValue) { | ||
downstream.receive(transform(value)) | ||
} | ||
|
||
override func terminate(_ termination: Termination<Error>) { | ||
downstream.terminate(termination) | ||
} | ||
} | ||
} |
Oops, something went wrong.