Reputation: 47
I need to write a Haskell program that takes an integer and a list and repeats the characters of the list up to n digits:
Int -> [a] -> [a]
e.g. 3 "pink"
would give "pin"
6 "blue"
would give "bluebl"
I'm new to the Haskell so cannot form the logic or don't know if there's any function to do it.
Upvotes: 2
Views: 258
Reputation: 33496
One simple implementation would be to use cycle
and take
:
takeRepeated :: Int -> [a] -> [a]
takeRepeated n = take n . cycle
Upvotes: 8