github.com/enetx/g@v1.0.80/types.go (about) 1 package g 2 3 import ( 4 "iter" 5 "os" 6 ) 7 8 type ( 9 // Result is a generic struct for representing a result value along with an error. 10 Result[T any] struct { 11 value *T // Pointer to the value. 12 err error // Associated error. 13 } 14 15 // Option is a generic struct for representing an optional value. 16 Option[T any] struct { 17 value *T // Pointer to the value. 18 } 19 20 // File is a struct that represents a file along with an iterator for reading lines. 21 File struct { 22 file *os.File // Underlying os.File. 23 name String // File name. 24 guard bool // Guard indicates whether the file is protected against concurrent access. 25 } 26 27 // Dir is a struct representing a directory path. 28 Dir struct { 29 path String // Directory path. 30 } 31 32 // String is an alias for the string type. 33 String string 34 35 // Int is an alias for the int type. 36 Int int 37 38 // Float is an alias for the float64 type. 39 Float float64 40 41 // Bytes is an alias for the []byte type. 42 Bytes []byte 43 44 // Slice is a generic alias for a slice. 45 Slice[T any] []T 46 47 // Map is a generic alias for a map. 48 Map[K comparable, V any] map[K]V 49 50 // Set is a generic alias for a set implemented using a map. 51 Set[T comparable] map[T]struct{} 52 53 // Pair is a struct representing a key-value Pair for MapOrd. 54 Pair[K, V any] struct { 55 Key K // Key of the pair. 56 Value V // Value associated with the key. 57 } 58 59 // MapOrd is a generic alias for a slice of ordered key-value pairs. 60 MapOrd[K, V any] []Pair[K, V] 61 62 // SeqSet is an iterator over sequences of unique values. 63 SeqSet[V comparable] iter.Seq[V] 64 65 // SeqSlice is an iterator over sequences of individual values. 66 SeqSlice[V any] iter.Seq[V] 67 68 // SeqSlices is an iterator over slices of sequences of individual values. 69 SeqSlices[V any] iter.Seq[[]V] 70 71 // SeqMapOrd is an iterator over sequences of ordered pairs of values, most commonly ordered key-value pairs. 72 SeqMapOrd[K, V any] iter.Seq2[K, V] 73 74 // SeqMap is an iterator over sequences of pairs of values, most commonly key-value pairs. 75 SeqMap[K comparable, V any] iter.Seq2[K, V] 76 )