My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Functional type classes in Swift

Benjamin Herzog's photo
Benjamin Herzog
·Jun 26, 2017

As an exercise I tried to declare some protocols of functional type classes in Swift, but I already failed on Functor, because protocols in Swift can't be generic.

Instead of this the official recommendation is to use associatedtypes, which is often the right choice. But in this case it's not possible to declare the return type like that.

protocol Functor[A] {

    func map[B](f: (A) -> B) -> Functor[B]

}