Last active
March 28, 2018 08:14
-
-
Save landonf/e01b51ce34766f4cfa98 to your computer and use it in GitHub Desktop.
An attempt to use the type inferencer to explicitly bind a protocol's typealias.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol TypeBinder { | |
typealias BoundT | |
} | |
class TypeEvidence<T> : TypeBinder { | |
typealias BoundT = T | |
func array () -> Array<BoundT> { return [] } | |
} | |
class ObserverTyper<T> { | |
class func bind <O: Observer where O.EventType == T> () -> TypeEvidence<O> { return TypeEvidence<O>() } | |
} | |
class Observable<T> : Stream<T> { | |
// Breaks the type inferencer? | |
// error: cannot convert the expression's type 'Array<$T2>' to type 'Observer' | |
var observers = ObserverTyper<T>.bind().array() | |
// but this works just fine ... so shouldn't the above work, too? | |
func sendExample<OT, O: Observer where O.EventType == OT> (value: OT) { | |
let observers = Array<O>() | |
for observer in observers { | |
observer.send(Event<OT>.Next(value)) | |
} | |
} | |
} | |
class Stream<T> { | |
} | |
protocol Observer { | |
typealias EventType | |
func send(Event<EventType>) | |
} | |
enum Event<T> { | |
case Next(T) | |
//case Error(NSError) | |
case Completed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment