Reputation: 450
I try extending SignalProducerType with SequenceType value. But I can't do. 'Type of expression is ambiguous without more context' error occurs in compiling.
protocol TranslatorType {
typealias Source
typealias Destination
func translate(source: Source) -> Destination
}
extension SignalProducerType where Value: SequenceType {
func translate<T: TranslatorType, U: SequenceType where T.Source == Value.Generator.Element, T.Destination == U.Generator.Element>(translator: T) -> ReactiveCocoa.SignalProducer<U, Error> {
return lift { $0.map { seq in seq.map(translator.translate) } } # Type of expression is ambiguous without more context error
}
}
How can I do that?
Upvotes: 0
Views: 104
Reputation: 4987
The map
function of SequenceType
returns an array, you can't map to a generic SequenceType
. Change type U
to an array, it can compile:
extension SignalProducerType where Value: SequenceType {
func translate<T: TranslatorType, V where T.Source == Value.Generator.Element, T.Destination == V>(translator: T) -> ReactiveCocoa.SignalProducer<[V], Error> {
return lift { $0.map { seq in seq.map(translator.translate) } }
}
}
Upvotes: 1