Skip to content

Instantly share code, notes, and snippets.

@tarunon
Created September 18, 2018 12:15
Show Gist options
  • Save tarunon/177547c2766db279e6b74cf9d5cde0fb to your computer and use it in GitHub Desktop.
Save tarunon/177547c2766db279e6b74cf9d5cde0fb to your computer and use it in GitHub Desktop.
struct User<T> { ... } // ←こういうものをConformしたい
extension Array where User<T> { ... } // ←これはまだできない
// ここからWorkaround
protocol UserProtocol { associatedtype T } // ←まずこれを作って
extension User: UserProtocol {} // Conformして
extension Array where Element: UserProtocol { // ←まずProtocolで縛って
func foo() where Element == User<Element.T> // ←さらに得られるassoctypeを使って二重に縛る。
}
[User<Int>]().foo() // OK
[User<String>]().foo() // OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment