Debian Codegraph @

comparator.go

raw symbols SCIP
1 package csv
2
3 // A RecordComparator is a function that returns true if the left Record is 'less' than the right Record
4 // according to some total order.
5 type RecordComparator func(l, r Record) bool
6
7 // Constructs a single RecordComparator from a slice of RecordComparators
8 func AsRecordComparator(comparators []RecordComparator) RecordComparator {
9 return func(l, r Record) bool {
10 for _, c := range comparators {
11 if c(l, r) {
12 return true
13 } else if c(r, l) {
14 return false
15 }
16 }
17 return false
18 }
19
20 }
21
22 // A StringComparator is a function that returns true if the left string is 'less' then the right string
23 // according to some total order.
24 type StringComparator func(l, r string) bool
25
26 // A StringSliceComparator is a function that returns true if the left slice is 'less' than the right slice
27 // according to some total order.
28 type StringSliceComparator func(l, r []string) bool
29
30 func AsStringSliceComparator(comparators []StringComparator) StringSliceComparator {
31 return func(l, r []string) bool {
32 for i, c := range comparators {
33 if c(l[i], r[i]) {
34 return true
35 } else if c(r[i], l[i]) {
36 return false
37 }
38 }
39 return false
40 }
41 }
42
43 // A Sort comparator compares two records, identified by i and j, and returns true if the ith record is
44 // less than the jth record according to some total order.
45 type SortComparator func(i, j int) bool