Skip to content

Commit 32efa48

Browse files
committed
catchToEffect updates
1 parent 3602b10 commit 32efa48

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ extension Effect {
152152
/// ```
153153
///
154154
/// - Parameters:
155-
/// - f: A mapping function that converts `Result<Output,Failure>` to another type.
155+
/// - transform: A mapping function that converts `Result<Value,Error>` to another type.
156156
/// - Returns: An effect that wraps `self`.
157-
public func catchToEffect<T>(_ f: @escaping (Result<Value, Error>) -> T) -> Effect<T,Never> {
157+
public func catchToEffect<T>(
158+
_ transform: @escaping (Result<Value, Error>) -> T
159+
) -> Effect<T,Never> {
158160
self
159-
.catchToEffect()
160-
.map(f)
161+
.map { transform(.success($0)) }
162+
.flatMapError { Effect<T, Never>(value: transform(.failure($0))) }
161163
}
162164

163165
/// Turns any publisher into an ``Effect`` for any output and failure type by ignoring all output

0 commit comments

Comments
 (0)