where

Posted by Genie on July 31, 2020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
struct Wrapper<T> {
    let value: T
    
    func base(){
        print(value)
    }
}


Wrapper(value: 5).base()

extension Wrapper {
    func isExtension(){
        print("extension \(value)")
    }
}

Wrapper.init(value: "hello").isExtension()

extension Wrapper where T: Equatable {
    func equatable (other: T) {
        print("Equatable: \(value) == \(other) -> \(value == other)")
    }
}

Wrapper(value: "bye").equatable(other: "bye bye")

extension Wrapper where T: Comparable {
    func compara(other: T) {
        print("Comparable \(value) < \(other) -> \(value < other)")
    }
}
Wrapper(value: 1).compara(other: 2)