Revision ed41c179 Ganeti/HTools/Types.hs

b/Ganeti/HTools/Types.hs
68 68
-- | Compute the maximum name length in an Element Container
69 69
cMaxNamelen :: (Element a) => Container.Container a -> Int
70 70
cMaxNamelen = maximum . map (length . name) . Container.elems
71

  
72
-- | Find an element by name in a Container; this is a very slow function
73
findByName :: (Element a, Monad m) =>
74
              Container.Container a -> String -> m Container.Key
75
findByName c n =
76
    let all_elems = Container.elems c
77
        result = filter ((== n) . name) all_elems
78
        nems = length result
79
    in
80
      if nems /= 1 then
81
          fail $ "Wrong number of elems (" ++ (show nems) ++
82
                   ") found with name " ++ n
83
      else
84
          return $ idx $ head result

Also available in: Unified diff