Created
February 5, 2015 04:52
-
-
Save STAR-ZERO/d5e1c6dfbd825d98cecb to your computer and use it in GitHub Desktop.
複数のOptionalをunwrap
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 Foundation | |
func unwrap2<T1, T2>(a: T1?, b: T2?) -> (T1, T2)? { | |
switch (a, b) { | |
case (let .Some(a), let .Some(b)): | |
return (a, b) | |
default: | |
return nil | |
} | |
} | |
func test(a: String?, b: String?) { | |
if let (_a, _b) = unwrap2(a, b) { | |
println("\(_a) : \(_b)") | |
} else { | |
println("nil") | |
} | |
} | |
test("a", "b") // a : b | |
test("a", nil) // nil | |
test(nil, "b") // nil | |
test(nil, nil) // nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment