Created
February 7, 2019 15:36
-
-
Save yannxou/6701991f894da7ae534fe46e36766601 to your computer and use it in GitHub Desktop.
Join array of optional strings (the functional way)
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
| struct Data { | |
| let name: String? | |
| let location: String? | |
| var components: String { | |
| return [name, location] | |
| .compactMap { $0 } | |
| .filter { !$0.isEmpty } | |
| .joined(separator: " - ") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment