use a foldr
Should be faster here.
This commit is contained in:
parent
1c9c9a0cee
commit
d7d9e9aca0
1 changed files with 7 additions and 7 deletions
|
@ -26,7 +26,7 @@ module PresenceLog (
|
|||
import Data.Time.Clock.POSIX
|
||||
import Data.Time
|
||||
import System.Locale
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Map as M
|
||||
import Control.Monad.State (liftIO)
|
||||
import Control.Applicative
|
||||
|
||||
|
@ -111,18 +111,18 @@ filterPresent = filter (\l -> InfoPresent == status l) . compactLog
|
|||
{- Compacts a set of logs, returning a subset that contains the current
|
||||
- status. -}
|
||||
compactLog :: [LogLine] -> [LogLine]
|
||||
compactLog = Map.elems . foldl mapLog Map.empty
|
||||
compactLog = M.elems . foldr mapLog M.empty
|
||||
|
||||
type LogMap = Map.Map String LogLine
|
||||
type LogMap = M.Map String LogLine
|
||||
|
||||
{- Inserts a log into a map of logs, if the log has better (ie, newer)
|
||||
- information than the other logs in the map -}
|
||||
mapLog :: LogMap -> LogLine -> LogMap
|
||||
mapLog m l =
|
||||
mapLog :: LogLine -> LogMap -> LogMap
|
||||
mapLog l m =
|
||||
if better
|
||||
then Map.insert i l m
|
||||
then M.insert i l m
|
||||
else m
|
||||
where
|
||||
better = maybe True newer $ Map.lookup i m
|
||||
better = maybe True newer $ M.lookup i m
|
||||
newer l' = date l' <= date l
|
||||
i = info l
|
||||
|
|
Loading…
Reference in a new issue