v2 / vlib / v / tests / fns / closure_fn_arg_in_map_test.v
19 lines · 17 sloc · 503 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Options {
2}
3
4fn sort_dictionary_order(mut lines []string, options Options) {
5 map_fn := fn (e u8) u8 {
6 return if e.is_digit() || e.is_letter() || e == ` ` { e } else { ` ` }
7 }
8 lines.sort_with_compare(fn [map_fn] (a &string, b &string) int {
9 aa := a.bytes().map(map_fn).bytestr()
10 bb := b.bytes().map(map_fn).bytestr()
11 return compare_strings(aa, bb)
12 })
13}
14
15fn test_main() {
16 mut a := ['a', 'b', 'c'].reverse()
17 sort_dictionary_order(mut a, Options{})
18 assert dump(a) == ['a', 'b', 'c']
19}
20