Last active
August 29, 2015 14:20
-
-
Save 0thernet/78c78364852396281a9c to your computer and use it in GitHub Desktop.
This file contains 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
import Cocoa | |
protocol Pet { | |
var name : String { get } | |
func renamed(newName: String) -> Self | |
} | |
struct Fish : Pet { | |
let name : String | |
func renamed(newName: String) -> Fish { | |
return Fish(name: newName) | |
} | |
} | |
struct Kitty : Pet { | |
let name : String | |
func renamed(newName: String) -> Kitty { | |
return Kitty(name: newName) | |
} | |
} | |
func esquire(a: Pet) -> Pet { | |
return a.renamed(a.name + ", Esq.") | |
} | |
let bob = Fish(name: "Bob") | |
let thor = Kitty(name: "Thor") | |
let pets : [Pet] = [bob, thor] | |
let esquires = pets.map { esquire($0) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment