github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xslice/zip.go (about)

     1  package xslice
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  type ZipItem struct {
     8  	Left  interface{}
     9  	Right interface{}
    10  }
    11  
    12  func Zip(a []interface{}, b []interface{}) []*ZipItem {
    13  	if len(a) != len(b) {
    14  		panic(fmt.Sprintf("len a is %d, len b is %d", len(a), len(b)))
    15  	}
    16  	items := make([]*ZipItem, 0, len(a))
    17  	for i, x := range a {
    18  		items = append(items, &ZipItem{
    19  			Left:  x,
    20  			Right: b[i],
    21  		})
    22  	}
    23  	return items
    24  }