-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(runtime): Move
TimeInterval
to its own module
- Loading branch information
1 parent
48a1532
commit 75ee08f
Showing
3 changed files
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
module Scheduler.TimeInterval where | ||
|
||
import Data.Set (Set) | ||
import qualified Data.Set as Set | ||
|
||
import StuntDouble.Time | ||
------------------------------------------------------------------------ | ||
-- does Time support inf? | ||
data TimeInterval = TimeInterval {tiFrom :: Time, tiTo :: Time} | ||
deriving stock (Eq, Ord, Show) | ||
|
||
contain :: Time -> TimeInterval -> Bool | ||
contain t (TimeInterval a b) = afterTime t a && afterTime b t | ||
|
||
-- I'm sure there is some clever data structure for this | ||
newtype TimeIntervals = TimeIntervals (Set TimeInterval) | ||
deriving newtype (Semigroup, Monoid, Show) | ||
|
||
emptyIntervals :: TimeIntervals | ||
emptyIntervals = TimeIntervals Set.empty | ||
|
||
singleton :: TimeInterval -> TimeIntervals | ||
singleton = TimeIntervals . Set.singleton | ||
|
||
contains :: Time -> TimeIntervals -> Bool | ||
contains t (TimeIntervals s) = | ||
not | ||
. Set.null | ||
. Set.filter (contain t) | ||
$ s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters