Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-| Returns a list of repeated applications of `f`.
- If `f` returns `Nothing` the iteration will stop. If it returns `Just y` then
- `y` will be added to the list and the iteration will continue with `f y`.
- nextYear : Int -> Maybe Int
- nextYear year =
- if year >= 2030 then
- Nothing
- else
- Just (year + 1)
- -- Will evaluate to [2010, 2011, ..., 2030]
- iterate nextYear 2010
- -}
- iterate : (a -> Maybe a) -> a -> List a
- iterate f x =
- case f x of
- Just x' -> x :: iterate f x'
- Nothing -> [x]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement