[英]Data.List.Split's `chunksOf` with 0 Value
Data.List.Split
's chunksOf
has the type: Data.List.Split
的chunksOf
具有以下类型:
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: 当我传递值
0
,它将返回一个空列表的无限列表:
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]]
? 不返回
Maybe [[a]]
的优点/原因是什么?
There is precisely one sensible way to produce chunks of size 0 from a list, so it does that. 正是有一种明智的方法可以从列表中生成大小为0的块,因此可以做到这一点。 It's not that useful, but it's better to produce something reasonable and useless than to deal with
Maybe
or throw exceptions. 它不是那么有用,但是产生合理且无用的东西比处理
Maybe
或引发异常更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.