Skip to content

Instantly share code, notes, and snippets.

@hiroshi-maybe
Created June 24, 2017 01:25
Show Gist options
  • Save hiroshi-maybe/04357eb71d4f79dfb353c15a019a5d12 to your computer and use it in GitHub Desktop.
Save hiroshi-maybe/04357eb71d4f79dfb353c15a019a5d12 to your computer and use it in GitHub Desktop.
protocol OptionalType {
associatedtype W
var optional: W? { get }
}
extension Optional: OptionalType {
typealias W = Wrapped
var optional: W? { return self }
}
extension Array where Element: OptionalType {
func unwrap() -> [Element.W] {
return flatMap { $0.optional }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment