Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created October 4, 2017 15:45
Show Gist options
  • Save mbrandonw/e5abe712f175a3a9f4a6cafd00eb3286 to your computer and use it in GitHub Desktop.
Save mbrandonw/e5abe712f175a3a9f4a6cafd00eb3286 to your computer and use it in GitHub Desktop.
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