From 88253d03246ddb741650aa92e9f193a27c91315b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 19 Jun 2011 05:46:58 +0300 Subject: [PATCH] htools: rewrite Cluster.filterMGResults filterMGResults was built using a sequence of map and filter calls; while this was logically correct, it used some incomplete pattern matching which with the new GHC 7 triggers a warning. The patch rewrites it using a single foldl that does both the filtering and the mapping, in a more type-safe way. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- htools/Ganeti/HTools/Cluster.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs index 1d18a1a87..10f34fdf3 100644 --- a/htools/Ganeti/HTools/Cluster.hs +++ b/htools/Ganeti/HTools/Cluster.hs @@ -685,16 +685,19 @@ solutionDescription gl (groupId, result) = pol = apolToString (Group.allocPolicy grp) -- | From a list of possibly bad and possibly empty solutions, filter --- only the groups with a valid result +-- only the groups with a valid result. Note that the result will be +-- reversed compared to the original list filterMGResults :: Group.List -> [(Gdx, Result AllocSolution)] -> [(Gdx, AllocSolution)] -filterMGResults gl= - filter ((/= AllocUnallocable) . Group.allocPolicy . - flip Container.find gl . fst) . - filter (not . null . asSolutions . snd) . - map (\(y, Ok x) -> (y, x)) . - filter (isOk . snd) +filterMGResults gl = foldl' fn [] + where unallocable = not . Group.isAllocable . flip Container.find gl + fn accu (gdx, rasol) = + case rasol of + Bad _ -> accu + Ok sol | null (asSolutions sol) -> accu + | unallocable gdx -> accu + | otherwise -> (gdx, sol):accu -- | Sort multigroup results based on policy and score sortMGResults :: Group.List -- GitLab