Last active
August 29, 2015 14:08
-
-
Save alexfish/f0d77bd46095c7688f5d to your computer and use it in GitHub Desktop.
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
extension Array { | |
func mapFilter<U>(transform: (T) -> U?) -> [U] { | |
var array: [U] = [] | |
for element in self { | |
if let mapped: U = transform(element) { | |
array.append(mapped) | |
} | |
} | |
return array | |
} | |
} |
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
extension Array { | |
mutating func unshift(match: T -> Bool) { | |
for index in 0...self.count { | |
var item = self[index] | |
if match(item) { | |
self.removeAtIndex(index) | |
self.insert(item, atIndex: 0) | |
break | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be called
filterNot