Created
September 15, 2023 06:29
-
-
Save adam-zethraeus/88cfeec5228508a418a39508e484d32a to your computer and use it in GitHub Desktop.
Codable/Hashable Tuple
This file contains 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
public enum Tup { | |
public struct A<A> { | |
var a: A | |
} | |
public struct B<A, B> { | |
var a: A | |
var b: B | |
} | |
public struct C<A, B, C> { | |
var a: A | |
var b: B | |
var c: C | |
} | |
public struct D<A, B, C, D> { | |
var a: A | |
var b: B | |
var c: C | |
var d: D | |
} | |
} | |
extension Tup { | |
public static func of<A>(_ a: A) -> Tup.A<A> { .init(a: a) } | |
public static func of<A, B>(_ a: A, b: B) -> Tup.B<A, B> { .init(a: a, b: b) } | |
public static func of<A, B, C>(_ a: A, _ b: B, _ c: C) -> Tup.C<A, B, C> { .init(a: a, b: b, c: c) } | |
public static func of<A, B, C, D>(_ a: A, _ b: B, _ c: C, _ d: D) -> Tup.D<A, B, C, D> { .init(a: a, b: b, c: c, d: d) } | |
} | |
extension Tup.A: Equatable where A: Equatable {} | |
extension Tup.A: Hashable where A: Hashable {} | |
extension Tup.A: Codable where A: Codable {} | |
extension Tup.B: Equatable where A: Equatable, B: Equatable {} | |
extension Tup.B: Hashable where A: Hashable, B: Hashable {} | |
extension Tup.B: Codable where A: Codable, B: Codable {} | |
extension Tup.C: Equatable where A: Equatable, B: Equatable, C: Equatable {} | |
extension Tup.C: Hashable where A: Hashable, B: Hashable, C: Hashable {} | |
extension Tup.C: Codable where A: Codable, B: Codable, C: Codable {} | |
extension Tup.D: Equatable where A: Equatable, B: Equatable, C: Equatable, D: Equatable {} | |
extension Tup.D: Hashable where A: Hashable, B: Hashable, C: Hashable, D: Hashable {} | |
extension Tup.D: Codable where A: Codable, B: Codable, C: Codable, D: Codable {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment