Created
June 16, 2014 05:05
-
-
Save jspahrsummers/7061ea467b767c4ae604 to your computer and use it in GitHub Desktop.
How a Functor hypothetically should be implemented in Swift(?)
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
protocol Functor { | |
typealias Element | |
func map<U, UF: Functor where UF.Element == U>(f: Element -> U) -> UF | |
} | |
struct FunctorImpl<T>: Functor { | |
typealias Element = T | |
var value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
func map<U>(f: T -> U) -> FunctorImpl<U> { | |
return FunctorImpl<U>(f(self.value)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment