QuickCombine provides additional operators and publishers to boost your productivity with Apple's Combine framework.
A minimum of Swift 5.1 is required to build QuickCombine (Xcode 11).
- Operators
-
Asynchronous Mapping:
-
Convenience Overloads:
-
Other:
-
-
This operator asynchronously maps each element for the upstream publisher to one output using promises. Upon the first promise being called,
futureMapwill ignore all subsequent promises and pass a finished completion state downstream. SincefutureMapcannot produce any errors, its error type isNever. For an operator with the same functionality asfutureMapbut with error propagation, seetryFutureMap.In the following example,
futureMapis used to retrieve the value at a specific location in a database.Just("Some/Database/Path") .futureMap { path, promise in getValueInDatabase(at: path) { value in promise((path, value)) } } .sink { (path, value) in print("The value of \(path) is \(value)") // Prints the location of the value and the value itself }
-
This operator is the same as
futureMapwith one notable exception,tryFutureMapallows errors to be propagated downstream. Because of this,tryFutureMap's promise takes a single argument of typeResult<Output, Upstream.Failure>.In the following example,
tryFutureMapis used to retrieve the value at a specific location in a database, passing any errors downstream. If the request succeeds, the value is printed, otherwise, the error message is printed.Just("Some/Database/Path") .setFailureType(to: DatabaseError.self) .tryFutureMap { path, promise in retrieveDatabaseValue(at: path) { result, error in if let error = error { promise(.failure(error)) } else { promise(.success(result!)) } } } .sink(receiveCompletion: { completion in if case let .failure(error) = completion { print(error.localizedDescription) } }, receiveValue: { value in print(value) })
In the case that throwing functions are used within the body of
tryFutureMap, theFailuretype of the resultant publisher will beError.
-