This file contains hidden or 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
| import UIKit | |
| struct Color: Codable { | |
| let r: Double | |
| let g: Double | |
| let b: Double | |
| } | |
| struct Point: Codable { | |
| let x: Double |
This file contains hidden or 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
| /* | |
| This gives the error: 'SomeGenericStruct' requires the types 'Self' and 'Self.SomeProtocolItemType.SomeProtocolElement' be equivalent | |
| */ | |
| protocol SomeProtocolItem { | |
| associatedtype SomeProtocolElement | |
| func apply(_ element: SomeProtocolElement) | |
| } |
This file contains hidden or 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
| // Paste me into a playground! | |
| import Cocoa | |
| //: # Basic Setup | |
| protocol FancyProtocol { | |
| associatedtype Thing | |
| func holdPinkyUp(x: Thing) | |
| } |
This file contains hidden or 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 Binder: Sequence { | |
| associatedtype Paper | |
| /* How do I force adoping types of Binder to be a Sequence that iterates over their Paper associated type? */ | |
| } | |
| struct Book: Binder { | |
| typealias Paper = ThickPaper | |
| } |
This file contains hidden or 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
| /* Binders should adopt Sequence */ | |
| protocol BinderProtocol : Sequence { | |
| associatedtyped Paper | |
| var width : Int { get } | |
| var height : Int { get } | |
| } | |
| // Paper types | |
| struct ThickPaper { |
This file contains hidden or 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
| /** Instead of this (PAT): **/ | |
| protocol Coin { | |
| associatedtyped Material | |
| } | |
| // Materials | |
| struct Silver { ... } | |
| struct Gold { ... } | |
| // Adoping types |