diff options
author | Gordon GECOS <u@adam> | 2023-03-20 07:58:34 -0400 |
---|---|---|
committer | Gordon GECOS <u@adam> | 2023-03-20 07:58:34 -0400 |
commit | 6b7597d8c744284c8fa63b4d755b8a428cc7098f (patch) | |
tree | 3ae7660fc5eeedef0576658426c822136d15d585 | |
parent | 68a28047dc5fea08ee23418a6293ef4d42aa9496 (diff) |
factor out function "buildCalendar"
-rw-r--r-- | CosmicCalendar.hs | 3 | ||||
-rw-r--r-- | CosmicCalendarEvents.hs | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/CosmicCalendar.hs b/CosmicCalendar.hs index bab94da..db29c02 100644 --- a/CosmicCalendar.hs +++ b/CosmicCalendar.hs | |||
@@ -123,6 +123,9 @@ type Calendar = Map NominalDiffTime CalendarEntry | |||
123 | getNextCalendarEntry :: Calendar -> LocalTime -> Maybe CalendarEntry | 123 | getNextCalendarEntry :: Calendar -> LocalTime -> Maybe CalendarEntry |
124 | getNextCalendarEntry cal (localTimeToYearElapsed -> t) = snd <$> Map.lookupGT t cal | 124 | getNextCalendarEntry cal (localTimeToYearElapsed -> t) = snd <$> Map.lookupGT t cal |
125 | 125 | ||
126 | buildCalendar :: [CalendarEntry] -> Map NominalDiffTime CalendarEntry | ||
127 | buildCalendar ls = Map.fromList $ map (\x -> (calBeginTime x, x)) $ map unwrap ls | ||
128 | |||
126 | unwrap :: CalendarEntry -> CalendarEntry | 129 | unwrap :: CalendarEntry -> CalendarEntry |
127 | unwrap x@CalendarEntry{..} = x { calDescription = unwrapText calDescription } | 130 | unwrap x@CalendarEntry{..} = x { calDescription = unwrapText calDescription } |
128 | where | 131 | where |
diff --git a/CosmicCalendarEvents.hs b/CosmicCalendarEvents.hs index 0973539..224fbe8 100644 --- a/CosmicCalendarEvents.hs +++ b/CosmicCalendarEvents.hs | |||
@@ -7,12 +7,11 @@ module CosmicCalendarEvents where | |||
7 | 7 | ||
8 | import Rebase.Prelude | 8 | import Rebase.Prelude |
9 | import NeatInterpolation | 9 | import NeatInterpolation |
10 | import qualified Rebase.Data.Map.Strict as Map | ||
11 | 10 | ||
12 | import CosmicCalendar | 11 | import CosmicCalendar |
13 | 12 | ||
14 | theCalendar :: Map NominalDiffTime CalendarEntry | 13 | theCalendar :: Map NominalDiffTime CalendarEntry |
15 | theCalendar = Map.fromList $ map (\x -> (calBeginTime x, x)) $ map unwrap | 14 | theCalendar = buildCalendar $ |
16 | [ | 15 | [ |
17 | CalendarEntry 0 Nothing "The Big Bang" "The universe begins" "" "", | 16 | CalendarEntry 0 Nothing "The Big Bang" "The universe begins" "" "", |
18 | CalendarEntry (370 & thousandYears & afterBigBang) | 17 | CalendarEntry (370 & thousandYears & afterBigBang) |