Documentation
¶
Index ¶
- func ChunkChannel[T any](ctx context.Context, input <-chan T, chunkSize int) <-chan []T
- func CmpVersion(a, b string) int
- func FilterFunc[T any](s []T, f func(T) bool) []T
- func LangCode(lang string) string
- func LangName(code string) string
- func Map[T any, U any](s []T, f func(T) U) []U
- func SliceMap[T comparable](s []T) map[T]int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChunkChannel ¶ added in v0.46.0
ChunkChannel transforms an input channel into a channel of slices, where each slice contains up to chunkSize items. It reads values from the input channel, groups them into slices of the specified size, and sends these slices to a new output channel. If the input channel closes, any remaining items are sent as a final slice, even if it’s smaller than chunkSize. The output channel is closed after all data has been processed.
**Parameters:**
- `input`: The channel (`<-chan T`) from which values of type T are read.
- `chunkSize`: The maximum number of items to include in each slice emitted to the output channel.
**Returns:**
- A channel (`<-chan []T`) that emits slices of type `[]T`, each containing up to `chunkSize` items from the input channel.
**Behavior:**
- Reads values from `input` and collects them into a slice.
- When the slice reaches `chunkSize`, it is sent to the output channel, and a new slice is started.
- If `input` closes, any remaining items (less than `chunkSize`) are sent as a final slice.
- The output channel is automatically closed after all data is processed.
**Example:** ```go input := make(chan int)
go func() { for i := 1; i <= 10; i++ { input <- i } close(input) }()
chunked := ChunkChannel(input, 3)
for chunk := range chunked { fmt.Println(chunk) }
// Output: // [1 2 3] // [4 5 6] // [7 8 9] // [10] ```
**Notes:**
- The function uses a goroutine to process the input channel asynchronously, ensuring it doesn’t block the caller.
- The type parameter `T` is generic, allowing `ChunkChannel` to work with any data type.
- The output channel is closed when the input channel is closed and all items have been processed, ensuring proper resource cleanup.
func CmpVersion ¶ added in v0.44.0
CmpVersion compares two semantic versions (eg v0.1.3 vs v0.2.0) as a and b. It returns 0 if the versions are equal, 1 if a is greater than b, and -1 if a is less than b. The version strings are expected to be in a format that can be split into integer components for comparison, such as "1.2.3" or "1.0.0".
func FilterFunc ¶ added in v0.32.0
Filter returns a new slice containing only the elements of s for which filter function returns true.
func Map ¶
Map applies a function to each element of a slice and returns a new slice in the same order.
func SliceMap ¶ added in v0.45.0
func SliceMap[T comparable](s []T) map[T]int
SliceMap takes a slice and returns back a lookup map which allows to find index for each element of the slice. If the value happens several times in the slice, the index corresponds to the first matching element.
Types ¶
This section is empty.
Directories
¶
Path | Synopsis |
---|---|
ent
|
|
reconciler
package reconciler describes entities for implementation of a Reconciliation Service API v0.2 https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410/
|
package reconciler describes entities for implementation of a Reconciliation Service API v0.2 https://www.w3.org/community/reports/reconciliation/CG-FINAL-specs-0.2-20230410/ |