Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension Array where Element: OptionalType {
- // Short hand for the original compactMap: we do not need to
- // pass in a selector function - instead just unwrap each
- // element in the Array to its base type.
- func compactMap() -> [Element.Wrapped] {
- return self.compactMap({$0.value})
- }
- }
- let a: [Int] = [0, 1, 2]
- // a.compactMap() - compile error.
- let b: [Int?] = [0, nil, 1, 2, nil]
- let c: [Int] = b.compactMap() // Returns [1, 2, 3]
Add Comment
Please, Sign In to add comment