Last active
November 22, 2017 08:56
-
-
Save Biacco42/965b21a2fd48aded199cf1558c78a831 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
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