[Haskell-cafe] Feeding a monad into itself
rein.henrichs at gmail.com
Thu Jul 20 18:03:48 UTC 2017
This is about as good as you can do. The monad-loops package provides a
variety of similar combinators, generally implemented in similar ways, but
not this specific combinator. The downside of this combinator is that it is
partial: it will run forever without producing anything if f never gives a
On Thu, Jul 20, 2017 at 10:27 AM Jake <jake.waksbaum at gmail.com> wrote:
> I have a function f :: a -> Maybe a that I want to feed into itself with
> some initial input until it returns Nothing.
> untilNothing :: (a -> Maybe a) -> a -> a
> untilNothing f x = case f x of
> Just x' -> untilNothing f x'
> Nothing -> x
> Is there a better way to do this? I feel like there is something more
> general going on with Monads being fed into themselves, but maybe I'm
> wrong. Thoughts?
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe