Gitly
English
Русский
Español
日本語
中文
Português
Log in
Register
v2
/
vlib
/
v
/
tests
/
generics
/
generics_struct_with_option_fn_test.v
14
lines
·
12
sloc
·
243 bytes
·
6488041a749df9762348d019c4223908c476f2e2
Raw
1
struct
Cmp[K] {
2
cmp ?
fn
(K, K) bool
3
}
4
5
fn
(c Cmp[K]) compare(a K, b K) bool {
6
cmp := c.cmp
or
{
return
a < b }
7
return
cmp(a, b)
8
}
9
10
fn
test_generic_struct_with_option_fn() {
11
c := Cmp[int]{}
12
print(c.compare(1, 2))
13
assert c.compare(1, 2)
14
}
15