Skip to content

Commit 18713e1

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 18713e1

File tree

1 file changed

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

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,18 @@ 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+
719+
712720
-- Get a list of the ledger state files order most recent
713721
listLedgerStateFilesOrdered :: LedgerStateDir -> IO [LedgerStateFile]
714722
listLedgerStateFilesOrdered dir = do

0 commit comments

Comments
 (0)