For a function f :: a -> GenericResult a, iterate it (in the sense of the
monad), until the result is Bad; return the list of values occurred.
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
, isBad
, eitherToResult
, annotateResult
+ , iterateOk
, select
, LookupResult(..)
, MatchPriority(..)
annotateResult owner (Bad s) = Bad $ owner ++ ": " ++ s
annotateResult _ v = v
+-- | Iterate while Ok.
+iterateOk :: (a -> GenericResult b a) -> a -> [a]
+iterateOk f a = genericResult (const []) ((:) a . iterateOk f) (f a)
+
-- * Misc functionality
-- | Return the first result with a True condition, or the default otherwise.