I have a function defined
maybeToList :: (a -> Maybe a) -> a -> [a]
maybeToList f x = x : maybe [] (maybeToList f) (f x)
This function seems so obvious that I can’t believe it is not standard.
Is it defined in some module (I already checked Data.Maybe)?
Your function isn’t in the standard libraries because it’s a specialized form of one that is:
That said, the case where the list elements are the same as the sequence of seed values is common, and it’s clumsy to write in terms of just
unfoldrand other standard functions, so I’m not sure why it’s not in the standard libraries as well.