coll overview
Compose lazy data processing and use slice, set, and map helpers for one-off transformations.
Use coll to filter, transform, and aggregate collections. Seq adds method chaining on top of the standard-library iter.Seq. A chain reads input only as you iterate or consume results. Use Seq.Collect to collect the results into a slice.
Installation
You need Go 1.27 or later. Run the installation command in your Go module.
go get github.com/luminyra/collChoose an operation
- Use
Fromto create aSeqfrom a slice. The genericSeq.Mapmethod can convert elements to another type. - Use
GroupByorPartitionwhen data is already in memory and you only need to group it or split it into two sets. - Use
Intersect,Difference, andUnionto compute set operations on slices.
Go standard library integration
Use slices.Chunk to batch a slice and maps.Keys to iterate over map keys. coll adds lazy method chains and set operations built around Go 1.27 iterators and generic methods. Most callbacks receive only the element. Use Seq.Indexed when you need the index.
Performance
In a benchmark that takes the first 100 matching IDs from 10,000 orders, a hand-written loop takes about 0.36 µs, a Seq pipeline takes about 0.52 µs, and Filter followed by Map over all the data takes about 29 µs. Seq stops once it has enough results. Use a hand-written loop on hot paths.
The quickstart uses one sequence of paid orders for several calculations.