diff --git a/library/Hasql/Deserialization/Result.hs b/library/Hasql/Deserialization/Result.hs index 3d3dab3..4a01427 100644 --- a/library/Hasql/Deserialization/Result.hs +++ b/library/Hasql/Deserialization/Result.hs @@ -182,7 +182,7 @@ foldl step init rowDes = maxCols <- LibPQ.nfields result accRef <- newIORef init failureRef <- newIORef Nothing - forM_ [0 .. pred (rowToInt maxRows)] $ \rowIndex -> do + forMFromZero_ (rowToInt maxRows) $ \rowIndex -> do rowResult <- Row.run rowDes (result, intToRow rowIndex, maxCols, integerDatetimes) case rowResult of Left x -> writeIORef failureRef (Just (RowError rowIndex x)) diff --git a/library/Hasql/Prelude.hs b/library/Hasql/Prelude.hs index eced2f3..b7e71eb 100644 --- a/library/Hasql/Prelude.hs +++ b/library/Hasql/Prelude.hs @@ -8,6 +8,7 @@ module Hasql.Prelude bug, bottom, forMToZero_, + forMFromZero_, strictCons, ) where @@ -122,6 +123,11 @@ forMToZero_ :: Applicative m => Int -> (Int -> m a) -> m () forMToZero_ !startN f = ($ pred startN) $ fix $ \loop !n -> if n >= 0 then f n *> loop (pred n) else pure () +{-# INLINE forMFromZero_ #-} +forMFromZero_ :: Applicative m => Int -> (Int -> m a) -> m () +forMFromZero_ !endN f = + ($ 0) $ fix $ \loop !n -> if n < endN then f n *> loop (succ n) else pure () + {-# INLINE strictCons #-} strictCons :: a -> [a] -> [a] strictCons !a b =