Skip to content

Commit 3b0661c

Browse files
committed
descriptions: Leverage ICU to get better description/payee/note sorting
1 parent 7e332fd commit 3b0661c

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

hledger/Hledger/Cli/Commands/Descriptions.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module Hledger.Cli.Commands.Descriptions (
1818
#if !(MIN_VERSION_base(4,11,0))
1919
import Data.Monoid
2020
#endif
21-
import Data.List
21+
import Data.List.Extra (nubSortBy)
22+
import qualified Data.Text.ICU as T
2223
import qualified Data.Text.IO as T
2324

2425
import Hledger
@@ -39,6 +40,6 @@ descriptions CliOpts{reportopts_=ropts} j = do
3940
d <- getCurrentDay
4041
let q = queryFromOpts d ropts
4142
ts = entriesReport ropts q j
42-
descriptions = nub $ sort $ map tdescription ts
43+
descriptions = nubSortBy (T.compare [T.CompareIgnoreCase]) $ map tdescription ts
4344

4445
mapM_ T.putStrLn descriptions

hledger/Hledger/Cli/Commands/Notes.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module Hledger.Cli.Commands.Notes (
1818
#if !(MIN_VERSION_base(4,11,0))
1919
import Data.Monoid
2020
#endif
21-
import Data.List
21+
import Data.List.Extra (nubSortBy)
22+
import qualified Data.Text.ICU as T
2223
import qualified Data.Text.IO as T
2324

2425
import Hledger
@@ -39,6 +40,6 @@ notes CliOpts{reportopts_=ropts} j = do
3940
d <- getCurrentDay
4041
let q = queryFromOpts d ropts
4142
ts = entriesReport ropts q j
42-
notes = nub $ sort $ map transactionNote ts
43+
notes = nubSortBy (T.compare [T.CompareIgnoreCase]) $ map transactionNote ts
4344

4445
mapM_ T.putStrLn notes

hledger/Hledger/Cli/Commands/Payees.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module Hledger.Cli.Commands.Payees (
1818
#if !(MIN_VERSION_base(4,11,0))
1919
import Data.Monoid
2020
#endif
21-
import Data.List
21+
import Data.List.Extra (nubSortBy)
22+
import qualified Data.Text.ICU as T
2223
import qualified Data.Text.IO as T
2324

2425
import Hledger
@@ -39,6 +40,6 @@ payees CliOpts{reportopts_=ropts} j = do
3940
d <- getCurrentDay
4041
let q = queryFromOpts d ropts
4142
ts = entriesReport ropts q j
42-
payees = nub $ sort $ map transactionPayee ts
43+
payees = nubSortBy (T.compare [T.CompareIgnoreCase]) $ map transactionPayee ts
4344

4445
mapM_ T.putStrLn payees

hledger/hledger.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ library
159159
, data-default >=0.5
160160
, directory
161161
, easytest >=0.2.1 && <0.3
162+
, extra
162163
, filepath
163164
, hashable >=1.2.4
164165
, haskeline >=0.6
@@ -179,6 +180,7 @@ library
179180
, tabular >=0.2
180181
, temporary
181182
, text >=0.11
183+
, text-icu
182184
, time >=1.5
183185
, timeit
184186
, transformers

hledger/package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ dependencies:
119119
- Decimal
120120
- directory
121121
- easytest >= 0.2.1 && <0.3
122+
- extra
122123
- filepath
123124
- haskeline >=0.6
124125
- megaparsec >=7.0.0 && <8
@@ -136,6 +137,7 @@ dependencies:
136137
- tabular >=0.2
137138
- temporary
138139
- text >=0.11
140+
- text-icu
139141
- time >=1.5
140142
- timeit
141143
- transformers

0 commit comments

Comments
 (0)