Revision bfe6c954 htools/Ganeti/HTools/Utils.hs
b/htools/Ganeti/HTools/Utils.hs | ||
---|---|---|
28 | 28 |
, debugXy |
29 | 29 |
, sepSplit |
30 | 30 |
, stdDev |
31 |
, if' |
|
32 |
, select |
|
31 | 33 |
, commaJoin |
32 | 34 |
, readEitherString |
33 | 35 |
, JSRecord |
... | ... | |
106 | 108 |
av = foldl' (\accu em -> let d = em - mv in accu + d * d) 0.0 lst |
107 | 109 |
in sqrt (av / ll) -- stddev |
108 | 110 |
|
111 |
-- * Logical functions |
|
112 |
|
|
113 |
-- Avoid syntactic sugar and enhance readability. These functions are proposed |
|
114 |
-- by some for inclusion in the Prelude, and at the moment they are present |
|
115 |
-- (with various definitions) in the utility-ht package. Some rationale and |
|
116 |
-- discussion is available at <http://www.haskell.org/haskellwiki/If-then-else> |
|
117 |
|
|
118 |
-- | \"if\" as a function, rather than as syntactic sugar. |
|
119 |
if' :: Bool -- ^ condition |
|
120 |
-> a -- ^ \"then\" result |
|
121 |
-> a -- ^ \"else\" result |
|
122 |
-> a -- ^ \"then\" or "else" result depending on the condition |
|
123 |
if' True x _ = x |
|
124 |
if' _ _ y = y |
|
125 |
|
|
126 |
-- | Return the first result with a True condition, or the default otherwise. |
|
127 |
select :: a -- ^ default result |
|
128 |
-> [(Bool, a)] -- ^ list of \"condition, result\" |
|
129 |
-> a -- ^ first result which has a True condition, or default |
|
130 |
select def = maybe def snd . find fst |
|
131 |
|
|
109 | 132 |
-- * JSON-related functions |
110 | 133 |
|
111 | 134 |
-- | A type alias for the list-based representation of J.JSObject. |
Also available in: Unified diff