Skip to content

Commit

Permalink
Use Int to count chunks in inits
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysxia committed Mar 17, 2024
1 parent 6dd5613 commit c905ac8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ module Data.Text.Lazy
-- , sort
) where

import Prelude (Char, Bool(..), Maybe(..), String,
import Prelude (Char, Bool(..), Int, Maybe(..), String,
Eq, (==), Ord(..), Ordering(..), Read(..), Show(..),
Monad(..), pure, (<$>),
(&&), (+), (-), (.), ($), (++),
Expand Down Expand Up @@ -1445,14 +1445,14 @@ inits = (NE.toList P.$!) . initsNE
initsNE :: Text -> NonEmpty Text
initsNE ts0 = Empty NE.:| inits' 0 ts0
where
inits' :: Int64 -- Number of previous chunks i
inits' :: Int -- Number of previous chunks i
-> Text -- The remainder after dropping i chunks from ts0
-> [Text] -- Prefixes longer than the first i chunks of ts0.
inits' !i (Chunk t ts) = L.map (takeChunks i ts0) (NE.tail (T.initsNE t))
++ inits' (i + 1) ts
inits' _ Empty = []

takeChunks :: Int64 -> Text -> T.Text -> Text
takeChunks :: Int -> Text -> T.Text -> Text
takeChunks !i (Chunk t ts) lastChunk | i > 0 = Chunk t (takeChunks (i - 1) ts lastChunk)
takeChunks _ _ lastChunk = Chunk lastChunk Empty

Expand Down

0 comments on commit c905ac8

Please sign in to comment.