PRELUSE: add sortLexSwapped

This commit is contained in:
hasufell 2015-01-08 01:38:32 +01:00
parent 1dd4dd6f59
commit 79175d7fa0
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 8 additions and 0 deletions

View File

@ -40,6 +40,14 @@ sortLex =
x -> x)
-- |Sort a list of tuples lexicographically, but start with second elem.
sortLexSwapped :: (Ord a) => [(a, a)] -> [(a, a)]
sortLexSwapped =
sortBy (\(x1, y1) (x2, y2) -> case compare y1 y2 of
EQ -> compare x1 x2
y -> y)
-- |Get the last x elements of a list.
getLastX :: Int -> [a] -> [a]
getLastX a xs