Skip to content

Commit f2c1b25

Browse files
committed
update: README.md
1 parent c08900c commit f2c1b25

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
# chunk
1+
# What is this?
2+
Obtains an index of specified size length and returns it.
3+
4+
# Usage
5+
6+
```go
7+
package main
8+
9+
import (
10+
"fmt"
11+
12+
"github.com/go-utils/chunk"
13+
)
14+
15+
func main() {
16+
arr := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
17+
18+
chunkedArr := make([][]int, 0)
19+
// chunk size is 3
20+
for idx := range chunk.GetIndex(len(arr), 3) {
21+
chunkedArr = append(chunkedArr, arr[idx.From:idx.To])
22+
}
23+
24+
fmt.Printf("%#v\n", chunkedArr)
25+
// Output: [][]int{[]int{1, 2, 3}, []int{4, 5, 6}, []int{7, 8, 9}, []int{10}}
26+
}
27+
```
28+
29+
## License
30+
- Under the [MIT License](./LICENSE)
31+
- Copyright (C) 2022 go-utils

0 commit comments

Comments
 (0)