Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created June 24, 2014 09:40
Show Gist options
  • Save fjolnir/7946e18e022f3a59a850 to your computer and use it in GitHub Desktop.
Save fjolnir/7946e18e022f3a59a850 to your computer and use it in GitHub Desktop.
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