/
ids.go
41 lines (33 loc) · 898 Bytes
/
ids.go
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
35
36
37
38
39
40
41
package uu
import (
"database/sql/driver"
"encoding/json"
"fmt"
"github.com/domonda/go-pretty"
)
var (
_ IDs = IDSet{}
_ IDs = IDSlice{}
)
// IDs is an interface implemented by IDSet and IDSlice
// as abstract collection of IDs.
// It is intended for passing IDs as input arguments,
// but does not support scanning or unmarshalling.
type IDs interface {
fmt.Stringer
pretty.Printable
driver.Valuer
json.Marshaler
// Len returns the length of the ID collection.
Len() int
// AsSet returns the contained IDs as IDSet.
AsSet() IDSet
// AsSlice returns the contained IDs as IDSlice.
AsSlice() IDSlice
// ForEach calls the passed function for each ID.
// Any error from the callback function is returned
// by ForEach immediatly.
// Returning a sentinel error is a way to stop the loop
// with a known cause that might not be a real error.
ForEach(func(ID) error) error
}