diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index 1235c33ee..d67f0d97d 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -75,9 +75,8 @@ import Data.Default import Data.Either (isRight) import Data.Functor.Identity (Identity) import "base-compat-batteries" Data.List.Compat -import Data.List.Extra (nubSort) +import Data.List.Extra (groupSortOn, nubSort) import Data.List.Split (splitOneOf) -import Data.Ord import Data.Maybe --import Data.String.Here -- import Data.Text (Text) @@ -662,12 +661,11 @@ registerWidthsFromOpts CliOpts{width_=Just s} = hledgerAddons :: IO [String] hledgerAddons = do -- past bug generator - as1 <- hledgerExecutablesInPath -- ["hledger-check","hledger-check-dates","hledger-check-dates.hs","hledger-check.hs","hledger-check.py"] - let as2 = map stripPrognamePrefix as1 -- ["check","check-dates","check-dates.hs","check.hs","check.py"] - let as3 = sortBy (comparing takeBaseName) as2 -- ["check","check.hs","check.py","check-dates","check-dates.hs"] - let as4 = groupBy (\a b -> takeBaseName a == takeBaseName b) as3 -- [["check","check.hs","check.py"],["check-dates","check-dates.hs"]] - let as5 = concatMap dropRedundantSourceVersion as4 -- ["check","check.hs","check.py","check-dates"] - return as5 + as1 <- hledgerExecutablesInPath -- ["hledger-check","hledger-check-dates","hledger-check-dates.hs","hledger-check.hs","hledger-check.py"] + let as2 = map stripPrognamePrefix as1 -- ["check","check-dates","check-dates.hs","check.hs","check.py"] + let as3 = groupSortOn takeBaseName as2 -- [["check","check.hs","check.py"],["check-dates","check-dates.hs"]] + let as4 = concatMap dropRedundantSourceVersion as3 -- ["check","check.hs","check.py","check-dates"] + return as4 stripPrognamePrefix = drop (length progname + 1) diff --git a/hledger/Hledger/Cli/Commands/Diff.hs b/hledger/Hledger/Cli/Commands/Diff.hs index 03de1086e..155cee359 100644 --- a/hledger/Hledger/Cli/Commands/Diff.hs +++ b/hledger/Hledger/Cli/Commands/Diff.hs @@ -12,7 +12,7 @@ module Hledger.Cli.Commands.Diff ( ,diff ) where -import Data.List ((\\), groupBy, nubBy, sortBy) +import Data.List.Extra ((\\), groupSortOn, nubBy, sortBy) import Data.Function (on) import Data.Ord (comparing) import Data.Maybe (fromJust) @@ -56,14 +56,11 @@ allPostingsWithPath j = do (pidx, p) <- zip [0..] $ tpostings txn return PostingWithPath { ppposting = p, pptxnidx = txnidx, pppidx = pidx } -binBy :: Ord b => (a -> b) -> [a] -> [[a]] -binBy f = groupBy ((==) `on` f) . sortBy (comparing f) - combine :: ([a], [b]) -> [Either a b] combine (ls, rs) = map Left ls ++ map Right rs combinedBinBy :: Ord b => (a -> b) -> ([a], [a]) -> [([a], [a])] -combinedBinBy f = map partitionEithers . binBy (either f f) . combine +combinedBinBy f = map partitionEithers . groupSortOn (either f f) . combine greedyMaxMatching :: (Eq a, Eq b) => [(a,b)] -> [(a,b)] greedyMaxMatching = greedyMaxMatching' [] diff --git a/tools/listbydeps.hs b/tools/listbydeps.hs index 5443b01cc..5bc836444 100755 --- a/tools/listbydeps.hs +++ b/tools/listbydeps.hs @@ -56,5 +56,5 @@ main = do [ base, pkgFile ] <- getArgs mods <- mapM (allDeps base) pkgs let deps = zip pkgs mods let deps' = sortBy (comparing fst) deps - mapM_ (print . fst) (sortBy (comparing $ length . snd) deps') + mapM_ (print . fst) (sortOn (length . snd) deps')