Commit a1da8a50 authored by Klaus Aehlig's avatar Klaus Aehlig

Add a function to leave the list monad

The list monad provides convenient syntax for non-deterministic
algorithms. Add a function leaving that monad with this intuition
in mind.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent c2b8d366
......@@ -48,6 +48,7 @@ module Ganeti.BasicTypes
, handleErrorT
, iterateOk
, select
, runListHead
, LookupResult(..)
, MatchPriority(..)
, lookupName
......@@ -312,6 +313,12 @@ select :: a -- ^ default result
-> a -- ^ first result which has a True condition, or default
select def = maybe def snd . find fst
-- | Apply a function to the first element of a list, return the default
-- value, if the list is empty. This is just a convenient combination of
-- maybe and listToMaybe.
runListHead :: a -> (b -> a) -> [b] -> a
runListHead a f = maybe a f . listToMaybe
-- * Lookup of partial names functionality
-- | The priority of a match in a lookup result.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment