Skip to content

Instantly share code, notes, and snippets.

@jckarter
Created May 25, 2016 01:07
Show Gist options
  • Save jckarter/2762c4fe91d8eba4b1ce27060b4c601d to your computer and use it in GitHub Desktop.
Save jckarter/2762c4fe91d8eba4b1ce27060b4c601d to your computer and use it in GitHub Desktop.
prefix operator * {}
/// Force-cast an Any to the type demanded by static context.
prefix func *<T>(x: Any) -> T {
return x as! T
}
var x: Any = 2
1 + *x
x = "world"
"hello " + *x
infix operator => {}
/// Dynamically dispatch a method on Any.
func =><T, U, V>(myself: Any, method: T -> U -> V) -> U -> V {
return method(myself as! T)
}
(x=>String.hasPrefix)("wor")
@mishagray
Copy link

This is madness. Someone contact the Type Safe police...

@erica
Copy link

erica commented Jun 7, 2016

@jckarter

func =><T, U, V>(myself: Any, method: (T) -> (U) -> V) -> U -> V

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment