Created
December 28, 2015 01:40
-
-
Save oisdk/4c40958d341952fde5af 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
let dict = [1:"a", 2:"b"] | |
let key: Int? = 2 | |
if let value = key.map({ dict[$0] }) { | |
print(value) // "Optional("b")" | |
} | |
if let key = key, value = dict[key] { | |
print(value) // "b" | |
} | |
if let value = key.flatMap({dict[$0]}) { | |
print(value) // "b" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment