mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions Created the Join, JoinProjection, Range, SumMap, Zip functions, ecah fuction is documented with how it works and had a unit test or maybe more
20 lines
592 B
Go
20 lines
592 B
Go
package underscore
|
|
|
|
// Zips two slices togther so all the elements of left slice are attached to the corresponding
|
|
// elements of the right slice, i.e. [one two three] [1 2 3 4] = [{one, 1} {two, 2} {three, 3}]
|
|
// the returned data will be the size of the smallest slice
|
|
func Zip[L any, R any](left []L, right []R) []Tuple[L, R] {
|
|
shortest := 0
|
|
if len(left) < len(right) {
|
|
shortest = len(left)
|
|
} else {
|
|
shortest = len(right)
|
|
}
|
|
|
|
results := make([]Tuple[L, R], shortest)
|
|
for i := 0; i < shortest; i++ {
|
|
results[i] = Tuple[L, R]{Left: left[i], Right: right[i]}
|
|
}
|
|
|
|
return results
|
|
}
|