Created
June 24, 2014 09:40
-
-
Save fjolnir/7946e18e022f3a59a850 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
protocol TypeEquality { | |
typealias From | |
typealias To | |
func apply(a: From) -> To | |
} | |
struct Refl<X> : TypeEquality { | |
typealias From = X | |
typealias To = X | |
func apply(a: From) -> To { | |
return a | |
} | |
} | |
extension Array { | |
func plusEverything<Ev: TypeEquality where Ev.From == T, Ev.To == Int>(ev: Ev, n: Int) -> Array<Int> { | |
return self.map({ ev.apply($0) + n }) | |
} | |
} | |
let x = [true] | |
println([true,false].plusEverything(Refl(), n:5)) | |
println([1,2,3].plusEverything(Refl(), n:5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment