我想知道是否有一个标准函数迭代一个函数,该函数返回一个(Maybe值)超过一个初始值,收集列表中的值,但是当它到达Nothing时结束列表。例如,可以实现此功能:
iterateMaybe f a = a : iterMaybe (f a) where
iterMaybe Nothing = []
iterMaybe (Just a) = a : iterMaybe (f a)
或略有不同:
iterateMaybe' f Nothing = []
iterateMaybe' f (Just a) = a : iterateMaybe' f (f a)
答案 0 :(得分:13)