Created
October 4, 2017 15:45
-
-
Save mbrandonw/e5abe712f175a3a9f4a6cafd00eb3286 to your computer and use it in GitHub Desktop.
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
class Function<B> { | |
func call<A>(_ a: A) -> B { | |
fatalError("unimplemented") | |
} | |
} | |
final class PrintInt: Function<Void> { | |
func call(_ a: Int) -> Void { | |
print(a) | |
} | |
} | |
final class PrintString: Function<Void> { | |
func call(_ a: String) -> Void { | |
print(a) | |
} | |
} | |
let fns = [ | |
PrintInt(), | |
PrintString() | |
] | |
(fns.first as? PrintInt)?.call(1) | |
(fns.last as? PrintString)?.call("hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment