mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
* feat: add Tap, Transpose, Unzip, ParallelReduce, and Replicate - Add Tap: for side effects/debugging in pipelines - Add Transpose: flip matrix rows and columns - Add Unzip: split tuple slice into two slices - Add ParallelReduce: parallel reduction (experimental) - Add Replicate: create n copies of a value Comprehensive tests included for all functions. Resolves Issues 21, 22, 23, 24, 25 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * test: improve ParallelReduce test coverage to 97.5% Add comprehensive tests covering: - Default workers (workers <= 0) - Negative workers - Error handling and propagation - Context cancellation during execution - Context timeout - Single element processing - Many workers (more workers than elements) - Benchmark for performance validation Coverage increased from 68.75% to 97.5% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
21 lines
462 B
Go
21 lines
462 B
Go
package underscore
|
|
|
|
// Unzip splits a slice of tuples into two separate slices.
|
|
// The inverse operation of Zip.
|
|
//
|
|
// Example: Unzip([Tuple{1,"a"}, Tuple{2,"b"}]) → ([1,2], ["a","b"])
|
|
func Unzip[L, R any](pairs []Tuple[L, R]) ([]L, []R) {
|
|
if len(pairs) == 0 {
|
|
return []L{}, []R{}
|
|
}
|
|
|
|
lefts := make([]L, len(pairs))
|
|
rights := make([]R, len(pairs))
|
|
|
|
for i, pair := range pairs {
|
|
lefts[i] = pair.Left
|
|
rights[i] = pair.Right
|
|
}
|
|
|
|
return lefts, rights
|
|
}
|