@@ -1651,51 +1651,6 @@ extension SignalProtocol {
16511651 }
16521652 }
16531653
1654- /// Apply `operation` to values from `self` with `success`ful results
1655- /// forwarded on the returned signal and `failure`s sent as failed events.
1656- ///
1657- /// - parameters:
1658- /// - operation: A closure that accepts a value and returns a `Result`.
1659- ///
1660- /// - returns: A signal that receives `success`ful `Result` as `value` event
1661- /// and `failure` as failed event.
1662- public func attempt( _ operation: @escaping ( Value ) -> Result < ( ) , Error > ) -> Signal < Value , Error > {
1663- return attemptMap { value in
1664- return operation ( value) . map {
1665- return value
1666- }
1667- }
1668- }
1669-
1670- /// Apply `operation` to values from `self` with `success`ful results mapped
1671- /// on the returned signal and `failure`s sent as failed events.
1672- ///
1673- /// - parameters:
1674- /// - operation: A closure that accepts a value and returns a result of
1675- /// a mapped value as `success`.
1676- ///
1677- /// - returns: A signal that sends mapped values from `self` if returned
1678- /// `Result` is `success`ful, `failed` events otherwise.
1679- public func attemptMap< U> ( _ operation: @escaping ( Value ) -> Result < U , Error > ) -> Signal < U , Error > {
1680- return Signal { observer in
1681- self . observe { event in
1682- switch event {
1683- case let . value( value) :
1684- operation ( value) . analysis (
1685- ifSuccess: observer. send ( value: ) ,
1686- ifFailure: observer. send ( error: )
1687- )
1688- case let . failed( error) :
1689- observer. send ( error: error)
1690- case . completed:
1691- observer. sendCompleted ( )
1692- case . interrupted:
1693- observer. sendInterrupted ( )
1694- }
1695- }
1696- }
1697- }
1698-
16991654 /// Throttle values sent by the receiver, so that at least `interval`
17001655 /// seconds pass between each, then forwards them on the given scheduler.
17011656 ///
@@ -2229,7 +2184,56 @@ extension SignalProtocol where Error == NoError {
22292184 . promoteErrors ( NewError . self)
22302185 . timeout ( after: interval, raising: error, on: scheduler)
22312186 }
2187+ }
2188+
2189+ extension SignalProtocol {
2190+ /// Apply `operation` to values from `self` with `success`ful results
2191+ /// forwarded on the returned signal and `failure`s sent as failed events.
2192+ ///
2193+ /// - parameters:
2194+ /// - operation: A closure that accepts a value and returns a `Result`.
2195+ ///
2196+ /// - returns: A signal that receives `success`ful `Result` as `value` event
2197+ /// and `failure` as failed event.
2198+ public func attempt( _ operation: @escaping ( Value ) -> Result < ( ) , Error > ) -> Signal < Value , Error > {
2199+ return attemptMap { value in
2200+ return operation ( value) . map {
2201+ return value
2202+ }
2203+ }
2204+ }
22322205
2206+ /// Apply `operation` to values from `self` with `success`ful results mapped
2207+ /// on the returned signal and `failure`s sent as failed events.
2208+ ///
2209+ /// - parameters:
2210+ /// - operation: A closure that accepts a value and returns a result of
2211+ /// a mapped value as `success`.
2212+ ///
2213+ /// - returns: A signal that sends mapped values from `self` if returned
2214+ /// `Result` is `success`ful, `failed` events otherwise.
2215+ public func attemptMap< U> ( _ operation: @escaping ( Value ) -> Result < U , Error > ) -> Signal < U , Error > {
2216+ return Signal { observer in
2217+ self . observe { event in
2218+ switch event {
2219+ case let . value( value) :
2220+ operation ( value) . analysis (
2221+ ifSuccess: observer. send ( value: ) ,
2222+ ifFailure: observer. send ( error: )
2223+ )
2224+ case let . failed( error) :
2225+ observer. send ( error: error)
2226+ case . completed:
2227+ observer. sendCompleted ( )
2228+ case . interrupted:
2229+ observer. sendInterrupted ( )
2230+ }
2231+ }
2232+ }
2233+ }
2234+ }
2235+
2236+ extension SignalProtocol where Error == NoError {
22332237 /// Apply a failable `operation` to values from `self` with successful
22342238 /// results forwarded on the returned signal and thrown errors sent as
22352239 /// failed events.
0 commit comments