Skip to content

Instantly share code, notes, and snippets.

@alexkent
Created January 26, 2015 11:53
Show Gist options
  • Save alexkent/2f0eea37274c1b51a3aa to your computer and use it in GitHub Desktop.
Save alexkent/2f0eea37274c1b51a3aa to your computer and use it in GitHub Desktop.
import Foundation
var strings = ["one", "two", "three", "four"]
extension Array {
func mapFilter<U>(transform: (T) -> U?) -> [U] {
var o = [U]()
for e in self {
if let p = transform(e) {
o.append(p)
}
}
return o
}
}
let n:[Int] = strings.mapFilter {
if countElements($0) < 4 {
return 1
}
return nil
}
n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment