Revision ebf38064 htools/Ganeti/HTools/Container.hs
b/htools/Ganeti/HTools/Container.hs | ||
---|---|---|
27 | 27 |
-} |
28 | 28 |
|
29 | 29 |
module Ganeti.HTools.Container |
30 |
( |
|
31 |
-- * Types |
|
32 |
Container |
|
33 |
, Key |
|
34 |
-- * Creation |
|
35 |
, IntMap.empty |
|
36 |
, IntMap.singleton |
|
37 |
, IntMap.fromList |
|
38 |
-- * Query |
|
39 |
, IntMap.size |
|
40 |
, IntMap.null |
|
41 |
, find |
|
42 |
, IntMap.findMax |
|
43 |
, IntMap.member |
|
44 |
-- * Update |
|
45 |
, add |
|
46 |
, addTwo |
|
47 |
, IntMap.map |
|
48 |
, IntMap.mapAccum |
|
49 |
, IntMap.filter |
|
50 |
-- * Conversion |
|
51 |
, IntMap.elems |
|
52 |
, IntMap.keys |
|
53 |
-- * Element functions |
|
54 |
, nameOf |
|
55 |
, findByName |
|
56 |
) where |
|
30 |
( -- * Types |
|
31 |
Container |
|
32 |
, Key |
|
33 |
-- * Creation |
|
34 |
, IntMap.empty |
|
35 |
, IntMap.singleton |
|
36 |
, IntMap.fromList |
|
37 |
-- * Query |
|
38 |
, IntMap.size |
|
39 |
, IntMap.null |
|
40 |
, find |
|
41 |
, IntMap.findMax |
|
42 |
, IntMap.member |
|
43 |
-- * Update |
|
44 |
, add |
|
45 |
, addTwo |
|
46 |
, IntMap.map |
|
47 |
, IntMap.mapAccum |
|
48 |
, IntMap.filter |
|
49 |
-- * Conversion |
|
50 |
, IntMap.elems |
|
51 |
, IntMap.keys |
|
52 |
-- * Element functions |
|
53 |
, nameOf |
|
54 |
, findByName |
|
55 |
) where |
|
57 | 56 |
|
58 | 57 |
import qualified Data.IntMap as IntMap |
59 | 58 |
|
... | ... | |
86 | 85 |
findByName :: (T.Element a, Monad m) => |
87 | 86 |
Container a -> String -> m a |
88 | 87 |
findByName c n = |
89 |
let all_elems = IntMap.elems c |
|
90 |
result = filter ((n `elem`) . T.allNames) all_elems |
|
91 |
in case result of |
|
92 |
[item] -> return item |
|
93 |
_ -> fail $ "Wrong number of elems found with name " ++ n |
|
88 |
let all_elems = IntMap.elems c |
|
89 |
result = filter ((n `elem`) . T.allNames) all_elems |
|
90 |
in case result of |
|
91 |
[item] -> return item |
|
92 |
_ -> fail $ "Wrong number of elems found with name " ++ n |
Also available in: Unified diff