wrotki
(Mariusz Borsa)
1
Found this piece of code somewhere on the net:
public protocol Functor {
/// (* -> *)
associatedtype FA: Functor = Self // HERE: - is it perhaps the same/shortcut for 'where FA == Self' ?
/// *
associatedtype A
/// fmap
func fmap(_ f: @escaping ((A) -> B)) -> FA where FA.A == B
}
Thanks, tried to locate it googling for the docs but failed miserably.
Mariusz
1 Like
dmt
(Dima Galimzianov)
2
It's a default for FA. When an implementation of the protocol doesn't declare FA - Self will be used.
Examples:
struct F1: Functor {}
struct F2: Functor {}
struct F3: Functor {
typealias FA = F2
}
F1.FA == F1 // FA is defaulted to `Self` which is `F1` here
F2.FA == F2 // FA is defaulted to `Self` which is `F2` here
F3.FA == F2 // FA is specified by the implementation, so it's `F2`
5 Likes
wrotki
(Mariusz Borsa)
3
Yes, that's what I was looking for, thanks!