我想创建将字符串拆分为子字符串列表的函数,其中每个子字符串的长度为 k:
*Main> split_string_to_kmers "some_text" 3
["som","ome","me_","e_t","_te","tex","ext"]
这是我的解决方案:
split_string_to_kmers s k = split_string_to_kmers_helper s k []
where split_string_to_kmers_helper [] k acc = acc
split_string_to_kmers_helper s k acc
| length s >= k = split_string_to_kmers_helper (tail s) k (acc ++ [(take k s)])
| otherwise = acc
我只是想知道是否有一种方法可以重写我的代码,这样它就会更加具体化。