Skip to content

Instantly share code, notes, and snippets.

@0thernet
Last active August 29, 2015 14:20
Show Gist options
  • Save 0thernet/78c78364852396281a9c to your computer and use it in GitHub Desktop.
Save 0thernet/78c78364852396281a9c to your computer and use it in GitHub Desktop.
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