Skip to content

Commit 647427b

Browse files
committed
Flip the argument order of Replace in window folds
1 parent 007fe33 commit 647427b

File tree

1 file changed

+7
-7
lines changed
  • core/src/Streamly/Internal/Data/Scanl

1 file changed

+7
-7
lines changed

core/src/Streamly/Internal/Data/Scanl/Window.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ import Prelude hiding (length, sum, minimum, maximum)
110110
data Incr a =
111111
Insert !a
112112
-- | Delete !a
113-
| Replace !a !a -- ^ Replace new old
113+
| Replace !a !a -- ^ Replace old new
114114

115115
instance Functor Incr where
116116
fmap f (Insert x) = Insert (f x)
@@ -164,7 +164,7 @@ incrScanWith n (Scanl step1 initial1 extract1 final1) =
164164

165165
step (SWRing rb st) a = do
166166
(rb1, old) <- RingArray.replace rb a
167-
r <- step1 st (Replace a old, rb1)
167+
r <- step1 st (Replace old a, rb1)
168168
return $
169169
case r of
170170
Partial s -> Partial $ SWRing rb1 s
@@ -205,7 +205,7 @@ incrScanWith n (Scanl step1 initial1 extract1 final1) =
205205
step (SWRing mba rh st) a = do
206206
(rb1@(RingArray _ _ rh1), old) <-
207207
RingArray.insert (RingArray mba (n * SIZE_OF(a)) rh) a
208-
r <- step1 st (Replace a old, rb1)
208+
r <- step1 st (Replace old a, rb1)
209209
return $
210210
case r of
211211
Partial s -> Partial $ SWRing mba rh1 s
@@ -252,7 +252,7 @@ incrRollingMapM f = Scanl.mkScanlM f1 initial
252252

253253
f1 _ (Insert a) = f Nothing a
254254
-- f1 _ (Delete _) = return Nothing
255-
f1 _ (Replace x y) = f (Just y) x
255+
f1 _ (Replace old new) = f (Just old) new
256256

257257
-- | Apply a pure function on the latest and the oldest element of the window.
258258
--
@@ -269,7 +269,7 @@ incrRollingMap f = Scanl.mkScanl f1 initial
269269

270270
f1 _ (Insert a) = f Nothing a
271271
-- f1 _ (Delete _) = Nothing
272-
f1 _ (Replace x y) = f (Just y) x
272+
f1 _ (Replace old new) = f (Just old) new
273273

274274
-------------------------------------------------------------------------------
275275
-- Sum
@@ -296,7 +296,7 @@ incrSumInt = Scanl step initial extract extract
296296

297297
step s (Insert a) = return $ Partial (s + a)
298298
-- step s (Delete a) = return $ Partial (s - a)
299-
step s (Replace new old) = return $ Partial (s + new - old)
299+
step s (Replace old new) = return $ Partial (s + new - old)
300300

301301
extract = return
302302

@@ -353,7 +353,7 @@ incrSum = Scanl step initial extract extract
353353
let incr = -new - err
354354
in add total incr
355355
-}
356-
step (Tuple' total err) (Replace new old) =
356+
step (Tuple' total err) (Replace old new) =
357357
-- XXX if (new - old) is large we may lose err
358358
let incr = (new - old) - err
359359
in add total incr

0 commit comments

Comments
 (0)