Last active
August 29, 2015 14:02
-
-
Save kimhunter/f979c913266223f8ed7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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