Skip to content

Commit fa18006

Browse files
Fix makeIndexMask
1. Create the list in correct order - it was reversed 2. Remove duplicate indices from the input
1 parent 8501802 commit fa18006

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/Streamly/Coreutils/Cut.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ stripLatin1 = Array.dropAround (isSpace . chr. fromIntegral)
8787
makeIndexMask :: [Int] -> [Bool]
8888
makeIndexMask indices =
8989
-- Sort would be O(n) if pre-sorted
90-
let xs1 = List.sort $ filter (>= 0) indices
90+
let xs1 = fmap List.head $ List.group $ List.sort $ filter (>= 0) indices
9191
in go 0 xs1 id
9292

9393
where
9494

9595
go _ [] ys = ys []
9696
go i old@(x:xs) ys =
9797
if i == x
98-
then go (i + 1) xs ((True :) . ys)
99-
else go (i + 1) old ((False :) . ys)
98+
then go (i + 1) xs (ys . (True :))
99+
else go (i + 1) old (ys . (False :))
100100

101101
-- | Zip the input stream with the supplied mask and keep only those elements
102102
-- which are True in the mask stream.

0 commit comments

Comments
 (0)