0

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 
tito
  • 3
  • 1

1 Answers1

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)
Taylor Fausak
  • 1,106
  • 8
  • 12