Skip to content

Commit 13759d1

Browse files
committed
Drop use of partial List functions
Ghc-9.10 and later warn about use of partial functions like `List.head`.
1 parent 44eceb0 commit 13759d1

File tree

1 file changed

+8
-1
lines changed
  • cardano-db-sync/src/Cardano/DbSync/Ledger

1 file changed

+8
-1
lines changed

cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,17 @@ listMemorySnapshots env = do
705705
case AS.toNewestFirst $ ledgerDbCheckpoints ldb of
706706
[] -> []
707707
[a] -> [a]
708-
ls -> [List.head ls, List.last ls]
708+
(h : ls) -> catMaybes [Just h, lastMaybe ls]
709709
notGenesis GenesisPoint = False
710710
notGenesis (BlockPoint _ _) = True
711711

712+
lastMaybe :: [a] -> Maybe a
713+
lastMaybe xs =
714+
case xs of
715+
[] -> Nothing
716+
[x] -> Just x
717+
(_ : ys) -> lastMaybe ys
718+
712719
-- Get a list of the ledger state files order most recent
713720
listLedgerStateFilesOrdered :: LedgerStateDir -> IO [LedgerStateFile]
714721
listLedgerStateFilesOrdered dir = do

0 commit comments

Comments
 (0)