Skip to content

Conversation

@andersio
Copy link
Member

@andersio andersio commented May 26, 2017

Preceded by #408.

This is useful when combining multiple signals with NoError in the mix, reducing the verbosity.

let (signal, _) = Signal<(), NoError>.pipe()

print(type(of: signal.promoteError(CocoaError.self)))
print(type(of: signal.promoteError()))
print(type(of: signal.promoteError() as Signal<(), CocoaError>))

// The promotion of the second operand is inferred.
print(type(of: Signal.zip(signal.promoteError(CocoaError.self), signal.promoteError())))

///
/// - returns: A signal that has an instantiatable `ErrorType`.
public func promoteErrors<F: Swift.Error>(_: F.Type) -> Signal<Value, F> {
public func promoteError<F: Swift.Error>(_: F.Type = F.self) -> Signal<Value, F> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

/// - _ An `ErrorType`.
///
/// - returns: A signal that has an instantiatable `ErrorType`.
public func promoteError(_: Error.Type = Error.self) -> Signal<Value, Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait why is this overload necessary?

Copy link
Member Author

@andersio andersio May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't necessary, just that it allows one adds promoteError to everything in a brute force manner, while not yielding extra Signals in cases with the identical error types. Say if you do:

SignalProducer<Int, CocoaError>.combineLatest(
    SignalProducer<Int, CocoaError>.empty.promoteError(),
    SignalProducer<Int, NoError>.empty.promoteError()
)

The resulting Signal graph would be equivalent to:

SignalProducer<Int, CocoaError>.combineLatest(
    SignalProducer<Int, CocoaError>.empty,
    SignalProducer<Int, NoError>.empty.promoteError()
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very much 👎 for that. Since when has RAC promoted brainless thinking? :P A user calling this operator when they shouldn't is likely an error and shouldn't be silenced IMO.

Copy link
Member Author

@andersio andersio May 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I should be more careful about my wordings. The overload does not add any capability, and is just a fast path when the compiler knows Self.Error is the Error of the return producer.

Say SignalProducer<Int, CocoaError>.empty.promoteError(CocoaError.self).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh that's right, because it's not possible to do negative conditions on extensions. This is a great idea then 👍

///
/// - returns: A producer that has an instantiatable `ErrorType`.
public func promoteError(_: Error.Type = Error.self) -> SignalProducer<Value, Error> {
return self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@NachoSoto
Copy link
Member

Can you add a test to cover this automatic inference?

@mdiep mdiep merged commit 53b9beb into master May 30, 2017
@mdiep mdiep deleted the promoteerror-v2 branch May 30, 2017 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants