@@ -328,7 +328,7 @@ extension Publisher {
328328 ///
329329 /// ```swift
330330 /// case .buttonTapped:
331- /// return fetchUser(id: 1)
331+ /// return environment. fetchUser(id: 1)
332332 /// .catchToEffect()
333333 /// .map(ProfileAction.userResponse)
334334 /// ```
@@ -340,31 +340,27 @@ extension Publisher {
340340 . eraseToEffect ( )
341341 }
342342
343- /// Turns any publisher into an ``Effect`` that cannot fail by wrapping its output and failure into
344- /// result and then applying passed in function to it.
343+ /// Turns any publisher into an ``Effect`` that cannot fail by wrapping its output and failure
344+ /// into a result and then applying passed in function to it.
345345 ///
346- /// This is a convenience operator for writing `catchToEffect()` followed by a `map()` .
346+ /// This is a convenience operator for writing ``Effect/catchToEffect()`` followed by a
347+ /// ``Effect/map(_:)-28ghh``.
347348 ///
348349 /// ```swift
349350 /// case .buttonTapped:
350- /// return fetchUser(id: 1)
351- /// .catchToEffect {
352- /// switch $0 {
353- /// case let .success(response):
354- /// return ProfileAction.updatedUser(response)
355- /// case let .failure(error):
356- /// return ProfileAction.failedUserUpdate(error)
357- /// }
358- /// }
351+ /// return environment.fetchUser(id: 1)
352+ /// .catchToEffect(ProfileAction.userResponse)
359353 /// ```
360354 ///
361355 /// - Parameters:
362- /// - f : A mapping function that converts `Result<Output,Failure>` to another type.
356+ /// - transform : A mapping function that converts `Result<Output,Failure>` to another type.
363357 /// - Returns: An effect that wraps `self`.
364- public func catchToEffect< T> ( _ f: @escaping ( Result < Output , Failure > ) -> T ) -> Effect < T , Never > {
358+ public func catchToEffect< T> (
359+ _ transform: @escaping ( Result < Output , Failure > ) -> T
360+ ) -> Effect < T , Never > {
365361 self
366- . catchToEffect ( )
367- . map ( f )
362+ . map { transform ( . success ( $0 ) ) }
363+ . catch { Just ( transform ( . failure ( $0 ) ) ) }
368364 . eraseToEffect ( )
369365 }
370366
0 commit comments