Skip to content

Commit

Permalink
Use patterns to clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
berewt committed Apr 1, 2023
1 parent 95cb5da commit eb4d6fb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions marconi-core/src/Marconi/Core/Experiment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import Data.Foldable (foldlM, foldrM, traverse_)
import Data.Functor (($>))
import Data.Functor.Compose (Compose (Compose, getCompose))
import Data.List (intersect)
import Data.Sequence (Seq, ViewR (EmptyR, (:>)), (<|))
import Data.Sequence (Seq (Empty, (:|>)), (<|))
import Data.Text (Text)


Expand Down Expand Up @@ -283,7 +283,6 @@ instance Applicative m => Resumable ListIndexer event m where

in pure $ addLatestIfNeeded (ix ^. latest) indexPoints


-- ** Mixed indexer

-- | An indexer that has at most '_blocksListIndexer' events in memory and put the older one in database.
Expand Down Expand Up @@ -696,9 +695,9 @@ instance

bufferEvent = (bufferSize +~ 1) . (buffer %~ (timedEvent <|))

pushAndGetOldest b = case Seq.viewr b of
EmptyR -> (timedEvent, b)
(buffer' :> e') -> (e', timedEvent <| buffer')
pushAndGetOldest = \case
Empty -> (timedEvent, Empty)
(buffer' :|> e') -> (e', timedEvent <| buffer')

in do
if not $ bufferIsFull indexer
Expand Down Expand Up @@ -768,9 +767,9 @@ aggregateAt indexer = let
reachAggregationPoint = indexer ^. currentDepth >= indexer ^. securityParam + indexer ^. aggregateEvery

dequeueNextAggregatePoint =
case Seq.viewr (indexer ^. nextAggregates) of
EmptyR -> Nothing
xs :> p -> Just (p, indexer & nextAggregates .~ xs)
case indexer ^. nextAggregates of
Empty -> Nothing
xs :|> p -> Just (p, indexer & nextAggregates .~ xs)

in guard reachAggregationPoint *> dequeueNextAggregatePoint

Expand Down

0 comments on commit eb4d6fb

Please sign in to comment.