简体   繁体   中英

Data.List.Split's `chunksOf` with 0 Value

Data.List.Split 's chunksOf has the type:

Prelude Data.List.Split> :t chunksOf
chunksOf :: Int -> [e] -> [[e]]

Simple example:

Prelude Data.List.Split> chunksOf 2 [1,2,3,4]
[[1,2],[3,4]]

When I pass in a value of 0 , it returns an infinite list of empty list's:

Prelude Data.List.Split> take 5 $ chunksOf 0 [1]
[[],[],[],[],[]]

What's the reason for this behavior? What's the advantage/reason for not returning a Maybe [[a]] ?

There is precisely one sensible way to produce chunks of size 0 from a list, so it does that. It's not that useful, but it's better to produce something reasonable and useless than to deal with Maybe or throw exceptions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM