Revision bf7ee7ad src/Ganeti/Utils.hs
b/src/Ganeti/Utils.hs | ||
---|---|---|
58 | 58 |
, splitEithers |
59 | 59 |
, recombineEithers |
60 | 60 |
, resolveAddr |
61 |
, monadicThe |
|
61 | 62 |
, setOwnerAndGroupFromNames |
62 | 63 |
, formatOrdinal |
63 | 64 |
, atomicWriteFile |
... | ... | |
423 | 424 |
exitIfEmpty _ (x:_) = return x |
424 | 425 |
exitIfEmpty s [] = exitErr s |
425 | 426 |
|
427 |
-- | Obtain the unique element of a list in an arbitrary monad. |
|
428 |
monadicThe :: (Eq a, Monad m) => String -> [a] -> m a |
|
429 |
monadicThe s [] = fail s |
|
430 |
monadicThe s (x:xs) |
|
431 |
| all (x ==) xs = return x |
|
432 |
| otherwise = fail s |
|
433 |
|
|
426 | 434 |
-- | Split an 'Either' list into two separate lists (containing the |
427 | 435 |
-- 'Left' and 'Right' elements, plus a \"trail\" list that allows |
428 | 436 |
-- recombination later. |
Also available in: Unified diff