Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Created June 16, 2014 05:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jspahrsummers/7061ea467b767c4ae604 to your computer and use it in GitHub Desktop.
Save jspahrsummers/7061ea467b767c4ae604 to your computer and use it in GitHub Desktop.
How a Functor hypothetically should be implemented in Swift(?)
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