Skip to content

Instantly share code, notes, and snippets.

@53ningen
Created July 16, 2016 06:51
Show Gist options
  • Save 53ningen/b0a0607013d994779a27f5e7b2ddcb4b to your computer and use it in GitHub Desktop.
Save 53ningen/b0a0607013d994779a27f5e7b2ddcb4b to your computer and use it in GitHub Desktop.
/// `* -> *`
public class K1<A> { public init() {} }
public protocol Functor {
associatedtype A
associatedtype B
associatedtype FB = K1<B>
func fmap(f : A -> B) -> FB
}
extension Array : Functor {
public typealias A = Element
public typealias B = Any
public typealias FB = [B]
public func fmap<B>(f : A -> B) -> [B] {
return self.map(f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment