Haskell take and drop at the same time

1.8k views Asked by At

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
1

There are 1 answers

1
Daniel Wagner On