{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, ViewPatterns #-}
module Data.AssocList.ListLike.Comparison
(
sortKeys
) where
import Data.AssocList.ListLike.Concept
import Prelude ()
import Data.Functor.Contravariant (Comparison (..), contramap)
import Data.ListLike (cons, uncons)
import qualified Data.ListLike as LL
sortKeys :: forall l a b. AssocList l a b
=> Comparison a -> l -> l
sortKeys :: Comparison a -> l -> l
sortKeys Comparison a
cmp =
let
cmp' :: Comparison (a, b)
cmp' = ((a, b) -> a) -> Comparison a -> Comparison (a, b)
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap (\(a
a, b
b) -> a
a) Comparison a
cmp
in
((a, b) -> (a, b) -> Ordering) -> l -> l
forall full item.
ListLike full item =>
(item -> item -> Ordering) -> full -> full
LL.sortBy (Comparison (a, b) -> (a, b) -> (a, b) -> Ordering
forall a. Comparison a -> a -> a -> Ordering
getComparison Comparison (a, b)
forall b. Comparison (a, b)
cmp')