thoas / go-funk

A modern Go utility library which provides helpers (map, find, contains, filter, ...)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chunk panics on size == 0 (division by zero)

kfreiman opened this issue · comments

There is no checks on Chunk's size is set to 0. Does it should return N empty arrays where N is len of the input? Or just empty array?

Or may it just panics if chunk's size is set to 0 ? (for me a 0 chunk's size is like a black hole)

commented

hi @kfreiman could you add an example of this issue?

Sure!

package main

import (
	"log"
	"github.com/thoas/go-funk"
)

func main() {
	size := 0
	chunks := funk.Chunk([]int{1, 2, 3}, size)
	log.Println(chunks)
}

It will produce

panic: runtime error: integer divide by zero

goroutine 1 [running]:
github.com/thoas/go-funk.Chunk(0x4a2ea0, 0xc00000c0a0, 0x0, 0xc00000c0a0, 0x493c69)
        /home/kirill/go/pkg/mod/github.com/thoas/go-funk@v0.4.0/transform.go:35 +0x625
main.main()
        /home/kirill/tmp/funk/main.go:10 +0x89