【发布时间】:2014-07-06 20:08:31
【问题描述】:
例如,我需要一个函数:
gather :: Int -> [a] -> [[a]]
gather n list = ???
gather 3 "Hello!" == ["Hel","ell","llo","ol!"].
我有一个可行的实现:
gather :: Int-> [a] -> [[a]]
gather n list =
unfoldr
(\x ->
if fst x + n > length (snd x) then
Nothing
else
Just
(take
n
(drop
(fst x)
(snd x)),
(fst x + 1, snd x)))
(0, list)
但我想知道语言中是否已经为此内置了一些东西?我扫描了 Data.List 但什么也没看到。
【问题讨论】:
标签: haskell