简体   繁体   中英

Haskell take and drop at the same time

I was wondering how can I achieve:

Taking the first n characters of a string then ++ (concatenating them with) drop these first n and take the next n and so on (without cutting words). I have tried function composition and $ but the only thing I get, is errors.

EDIT

I am trying to align the text left for a given column width (n), that's why I try not to cut words, but if there is a word at the number n , just take some chars before it and then use \\n to start again for the next line. My main problems so far are checking for the cut-words condition(I can use !! but should I use it in guards with map(-1) or how else) and implementing the recursion because as a base I got

take n s ++ "\n" ++ take n (drop n s)

and also the case where n is smaller than the longest word:

leftAlign n str = if n < ((maximum . map length . words) str) then "" else leftAlign n str

Data.List.Split.chunksOf执行此操作。

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