Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SignalProducerProtocol.then to the concrete type. #343

Merged
merged 1 commit into from
Apr 26, 2017

Conversation

andersio
Copy link
Member

@andersio andersio commented Apr 23, 2017

Follow-up to #304.

then(_:) is disambiguated by introducing two more specific variants.

return _then(replacement)
}

internal func _then<U>(_ replacement: SignalProducer<U, Error>) -> SignalProducer<U, Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Why have this?

Copy link
Member Author

@andersio andersio Apr 23, 2017

Choose a reason for hiding this comment

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

Not having this leads to infinite self recursion in the new overloads, given how Swift selects an overload for a given name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment that explains that?

@@ -2696,6 +2721,6 @@ extension SignalProducer {
}
}

return SignalProducer.attempt(operation)
return SignalProducer(operation)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add attempt as a label? Having so many unnamed initializers leads to ambiguity.

Copy link
Member Author

@andersio andersio Apr 23, 2017

Choose a reason for hiding this comment

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

A test case was added specifically for this set of overloads, and it doesn't appear to be ambiguous. Apparently having the return type as Self helps mitigate the ambiguity that would otherwise arise when you put these two static attempt in a concrete type extension, like SR-4436.

Moreover, it is expected to be primarily called with trailing closures anyway, and a label can't help in this regard.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the static func attempt name for that reason. It also lends itself to RACformatting.

SignalProducer
    .attempt {
        
    }
    .flatMap(.concat) {
        
    }

Is renaming this an essential part of the PR? If not, could we move it off the protocol here and discuss the renaming in a separate PR?

Copy link
Member Author

@andersio andersio Apr 24, 2017

Choose a reason for hiding this comment

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

It is. I will open a separate PR for it then.

This coincidentally dodged the return type ambiguity of SignalProducer.Type.attempt, which somehow managed to get through as a protocol extension [but not as a concrete type extension].

return _then(replacement)
}

internal func _then<U>(_ replacement: SignalProducer<U, Error>) -> SignalProducer<U, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment that explains that?

///
/// - returns: A producer that sends events from `self` and then from
/// `replacement` when `self` completes.
public func then(_ replacement: SignalProducer<Value, Error>) -> SignalProducer<Value, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This was added to provide a more specific variant for type inference? If so, can you add a // comment that documents that?

Is this inference covered by a test case?

@@ -2696,6 +2721,6 @@ extension SignalProducer {
}
}

return SignalProducer.attempt(operation)
return SignalProducer(operation)
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the static func attempt name for that reason. It also lends itself to RACformatting.

SignalProducer
    .attempt {
        
    }
    .flatMap(.concat) {
        
    }

Is renaming this an essential part of the PR? If not, could we move it off the protocol here and discuss the renaming in a separate PR?

@andersio andersio changed the title Move the last methods in the SignalProducer protocol to the concrete type. Move SignalProducerProtocol.then to the concrete type. Apr 24, 2017
@andersio
Copy link
Member Author

Addressed all comments.

@mdiep mdiep merged commit da62426 into master Apr 26, 2017
@mdiep mdiep deleted the producer-protocol-cleanup branch April 26, 2017 12:21
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.

3 participants