Skip to content

Instantly share code, notes, and snippets.

@kimhunter
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimhunter/f979c913266223f8ed7f to your computer and use it in GitHub Desktop.
Save kimhunter/f979c913266223f8ed7f to your computer and use it in GitHub Desktop.
import Cocoa
extension Array {
func myMap<A,B>(items: Array<A>, f:((A) -> B)) -> Array<B> {
var xs: Array<A> = items
return xs.count == 0 ? [] : [f(xs.removeAtIndex(0))] + myMap(xs,f)
}
func myMap<B>(f:((T) -> B)) -> Array<B> {
return myMap(self,f)
}
}
var a = [4,2,4,5].myMap({ $0 + 2 })
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment