<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Also this pattern does seem Maybe-specific, in that for the general Monad case there's not an obvious termination condition.</div><div><br></div><div>JEff</div><div><br>On Jul 20, 2017, at 11:03 AM, Rein Henrichs <<a href="mailto:rein.henrichs@gmail.com">rein.henrichs@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">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 Nothing.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 20, 2017 at 10:27 AM Jake <<a href="mailto:jake.waksbaum@gmail.com">jake.waksbaum@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have a function f :: a -> Maybe a that I want to feed into itself with some initial input until it returns Nothing.<div><div><br><div>untilNothing :: (a -> Maybe a) -> a -> a<br></div><div>untilNothing f x = case f x of</div></div></div><div> Just x' -> untilNothing f x'</div><div> Nothing -> x</div><div><br></div><div>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?</div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span>To (un)subscribe, modify options or view archives go to:</span><br><span><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a></span><br><span>Only members subscribed via the mailman list are allowed to post.</span></div></blockquote></body></html>