Skip to content

Instantly share code, notes, and snippets.

@Biacco42
Last active November 22, 2017 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Biacco42/965b21a2fd48aded199cf1558c78a831 to your computer and use it in GitHub Desktop.
Save Biacco42/965b21a2fd48aded199cf1558c78a831 to your computer and use it in GitHub Desktop.
class Po<Element> {
var element: Element?
init(element: Element) {
self.element = element
}
}
protocol ConstPo {
associatedtype Element
var element: Element? { get }
}
extension Po: ConstPo {}
func processPo<X: ConstPo>(po: X, process: (X.Element) -> Void) {
process(po.element!)
// po.element = nil // Compile error!
}
let po = Po(element: 42)
processPo(po: po) { (intValue: Int) in
print(intValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment