I find a lot of things I jigger together on my own that seem at all useful actually have a standard implementation that I just didn't know about, so was curious if anybody could say they've seen this type of thing used before:
It takes a monadic function and will fold it until a predicate is chosen by alternative then it returns the result of the predicate:
until :: (Monad m, Alternative m) => (a -> m a) -> (a -> m c) -> a -> m c
f `until` p = \a -> (f >=> (p `altF` (until f p))) a
where f1 `altF` f2 = \a -> f1 a <|> f2 a
I realize the name is a prelude collision, I'll probably name it something else but thought I'd first see if there's already a similar piece of functionality in a standard library I just don't know about..
Also I guess I'm curious if the compositional alternative I wrote is defined elsewhere or if any of this bit of functionality seems misguided to begin with. But the crux of my question is, is this implemented elsewhere or is something very similar implemented elsewhere perhaps