I am trying to use protocols with generics but having trouble with syntax. In my first example, I have a first protocol declared as
protocol Consumer {
typealias T
func accept(arg: T)
}
I then declare another protocol for executing Consumer as
protocol Scheduler {
func schedule<T>(consumer : Consumer<T>, arg: T)
}
However, I get error about 'Consumer' can only be used as generic constraint because it has Self or associated type requirement
Here is another example, I have a protocol as
protocol Observable {
typealias T
func map<U>(function : (T) -> U) -> Observable<U>
}
I am trying to define a function that converts T to U and then return Observable with U type but getting similar error as above.
Can someone suggest correct syntax because coming from Java background above code seemed natural to me.
Thanks.