Skip to content

Instantly share code, notes, and snippets.

@alexfish
Last active August 29, 2015 14:08
Show Gist options
  • Save alexfish/f0d77bd46095c7688f5d to your computer and use it in GitHub Desktop.
Save alexfish/f0d77bd46095c7688f5d to your computer and use it in GitHub Desktop.
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
}
}
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
}
}
}
}
@SimonRichardson
Copy link

This should be called filterNot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment