Skip to content

Commit 3f46653

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

File tree

1 file changed

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

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ 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+
| Replace1 !a !a -- ^ Replace old new
114114

115115
instance Functor Incr where
116116
fmap f (Insert x) = Insert (f x)
117117
-- fmap f (Delete x) = Delete (f x)
118-
fmap f (Replace x y) = Replace (f x) (f y)
118+
fmap f (Replace1 x y) = Replace1 (f x) (f y)
119119

120120
-------------------------------------------------------------------------------
121121
-- Utilities
@@ -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 (Replace1 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 (Replace1 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 _ (Replace1 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 _ (Replace1 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 (Replace1 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) (Replace1 old new) =
357357
-- XXX if (new - old) is large we may lose err
358358
let incr = (new - old) - err
359359
in add total incr
@@ -374,7 +374,7 @@ incrCount = Scanl.mkScanl step 0
374374

375375
step w (Insert _) = w + 1
376376
-- step w (Delete _) = w - 1
377-
step w (Replace _ _) = w
377+
step w (Replace1 _ _) = w
378378

379379
-- | Sum of the \(k\)th power of all the elements in a rolling window:
380380
--

0 commit comments

Comments
 (0)