On Mon, Aug 10, 2015 at 07:22:14PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
While only a special case of maximumBy, it is useful
to have this total function (as the signature ensures
two arguments). Also this signature fits better operations
like insertWith.
Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/Utils.hs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs
index be23541..8b78f73 100644
--- a/src/Ganeti/Utils.hs
+++ b/src/Ganeti/Utils.hs
@@ -97,6 +97,7 @@ module Ganeti.Utils
, ensurePermissions
, ordNub
, isSubsequenceOf
+ , maxBy
, threadDelaySeconds
) where
@@ -830,3 +831,10 @@ isSubsequenceOf [] _ = True
isSubsequenceOf _ [] = False
isSubsequenceOf a@(x:a') (y:b) | x == y = isSubsequenceOf a' b
| otherwise = isSubsequenceOf a b
+
+-- | Compute the maximum of two elements by a given order.
+-- As opposed to using `maximumBy`, is function is guaranteed
+-- to be total, as the signature enforces a non-empty list of
+-- arguments.
+maxBy :: (a -> a -> Ordering) -> a -> a -> a
+maxBy ord a b = maximumBy ord [a, b]
--
2.5.0.rc2.392.g76e840b
LGTM