github.com/kaiya/goutils@v1.0.1-0.20230226104005-4ae4a4dc3688/io/file/batch.go (about) 1 package file 2 3 func Slice2Records(cells []string, batchSize int) [][]string { 4 ret := make([][]string, 0) 5 rowCount := 0 6 rowCells := make([]string, 0, batchSize) 7 for _, cell := range cells { 8 rowCells = append(rowCells, cell) 9 rowCount++ 10 if rowCount%batchSize == 0 { 11 ret = append(ret, rowCells) 12 rowCells = make([]string, 0) 13 rowCount = 0 14 } 15 } 16 if rowCount != 0 { 17 ret = append(ret, rowCells) 18 } 19 return ret 20 } 21 22 func SingleColumn2Table(records [][]string, idx int) []string { 23 ret := make([]string, 0, len(records)) 24 for _, record := range records { 25 ret = append(ret, record[idx]) 26 } 27 return ret 28 }