'How can I repeat my function x times in my code? [duplicate]

I would like to repeat the stepcells a for b times. How can I make this ?

play :: Generation -> Int -> Maybe Generation
play a b 
 | b < 0 = Nothing
 | b == 0 = (Just a) 
 | otherwise = Just (stepCells a)  -- do it b times 


Solution 1:[1]

As Noughtmare suggests in their comment, iterate is a good solution to this problem. However you can also do it with manual recursion:

play :: Generation -> Int -> Maybe Generation
play a b 
 | b < 0 = Nothing
 | b == 0 = (Just a) 
 | otherwise = play (stepCells a) (b - 1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taylor Fausak