Created
December 6, 2016 10:26
-
-
Save ukitaka/793878b56a7427b9fd99377ca93b906d to your computer and use it in GitHub Desktop.
Swiftのパターンマッチも意外とできた(できないと思ってた)
This file contains hidden or 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
| func map2<A, B, C>(_ fa: Optional<A>, _ fb: Optional<B>, _ f: (A, B) -> C) -> Optional<C> { | |
| switch (fa, fb) { | |
| case (.some(let a), .some(let b)): // ここできると思わなかった... | |
| return .some(f(a, b)) | |
| default: | |
| return .none | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment