-8
README.md
-8
README.md
···
52
52
// provided and no with() calls are done then the resulting class
53
53
// will only include the default string which might not be favorable
54
54
defaults: [Variant(Primary)],
55
-
// Create a comparator to see when two top level keys are matching
56
-
comparator: fn(a: Key, b: Key) {
57
-
case a, b {
58
-
Size(_), Size(_) -> True
59
-
Variant(_), Variant(_) -> True
60
-
_, _ -> False
61
-
}
62
-
},
63
55
)
64
56
65
57
let class =
+1
gleam.toml
+1
gleam.toml
+2
manifest.toml
+2
manifest.toml
···
2
2
# You typically do not need to edit this file
3
3
4
4
packages = [
5
+
{ name = "comparator", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "comparator", source = "hex", outer_checksum = "62A817E00FF301CE780F03D0FEE0943D5881138B3852F1DEE2FB72381604F949" },
5
6
{ name = "glailwind_merge", version = "1.1.0", build_tools = ["gleam"], requirements = ["tails"], otp_app = "glailwind_merge", source = "hex", outer_checksum = "3A9B557E63D174A430950B9748180DF386C96DEAD1FD0E6891A98D3A76175C59" },
6
7
{ name = "gleam_stdlib", version = "0.63.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5E216C7D5E8BE22359C9D7DAA2CFBD66039BC12565542F34CD033C5BB57071ED" },
7
8
{ name = "gleeunit", version = "1.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "FDC68A8C492B1E9B429249062CD9BAC9B5538C6FBF584817205D0998C42E1DAC" },
···
10
11
]
11
12
12
13
[requirements]
14
+
comparator = { version = ">= 1.0.0 and < 2.0.0" }
13
15
glailwind_merge = { version = ">= 1.1.0 and < 2.0.0" }
14
16
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
15
17
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+3
-14
src/gva.gleam
+3
-14
src/gva.gleam
···
1
+
import comparator
1
2
import gleam/list
2
3
import gleam/string
3
4
···
6
7
default: String,
7
8
resolver: fn(a) -> String,
8
9
defaults: List(a),
9
-
comparator: fn(a, a) -> Bool,
10
10
using: List(a),
11
11
)
12
12
}
···
38
38
case defaults {
39
39
[default, ..defaults] -> {
40
40
let is_applied =
41
-
list.filter(using, fn(a) { class.comparator(a, default) })
41
+
list.filter(using, fn(a) { comparator.is_same_kind(a, default) })
42
42
|> list.length
43
43
> 0
44
44
case is_applied {
···
67
67
///
68
68
/// The resolver handles which types should go to which classes
69
69
///
70
-
/// The comparator checks when two top level keys are matching
71
-
///
72
70
///
73
71
/// ## Examples
74
72
///
···
113
111
/// // provided and no with() calls are done then the resulting class
114
112
/// // will only include the default string which might not be favorable
115
113
/// defaults: [Variant(Primary)],
116
-
/// // Create a comparator to see when two top level keys are matching
117
-
/// comparator: fn(a: Key, b: Key) {
118
-
/// case a, b {
119
-
/// Size(_), Size(_) -> True
120
-
/// Variant(_), Variant(_) -> True
121
-
/// _, _ -> False
122
-
/// }
123
-
/// },
124
114
/// )
125
115
///
126
116
/// let class =
···
137
127
pub fn gva(
138
128
default default: String,
139
129
resolver resolver: fn(a) -> String,
140
-
comparator comparator: fn(a, a) -> Bool,
141
130
defaults defaults: List(a),
142
131
) {
143
-
Class(default, resolver, defaults, comparator, [])
132
+
Class(default, resolver, defaults, [])
144
133
}
-14
test/gva_test.gleam
-14
test/gva_test.gleam
···
40
40
}
41
41
},
42
42
defaults: [],
43
-
comparator: fn(a: BasicKey, b: BasicKey) {
44
-
case a, b {
45
-
BasicSize(_), BasicSize(_) -> True
46
-
BasicVariant(_), BasicVariant(_) -> True
47
-
_, _ -> False
48
-
}
49
-
},
50
43
)
51
44
52
45
let class =
···
113
106
AdvancedVariant(AdvancedDefaultVariant),
114
107
AdvancedSize(AdvancedDefaultSize),
115
108
],
116
-
comparator: fn(a: AdvancedKey, b: AdvancedKey) {
117
-
case a, b {
118
-
AdvancedSize(_), AdvancedSize(_) -> True
119
-
AdvancedVariant(_), AdvancedVariant(_) -> True
120
-
_, _ -> False
121
-
}
122
-
},
123
109
)
124
110
}
125
111