This repository has been archived by the owner on Aug 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- factor log data structure out into its own module - some wonky event routing and too many mailboxes; need to compress to one foldp eventually
- Loading branch information
Showing
11 changed files
with
239 additions
and
64 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
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,84 @@ | ||
module Debugger.Model.Log | ||
( Log, empty, fromList, toList, append, last | ||
, mostRecentBeforeIndex, truncate, map, filter, isEmpty, update | ||
) where | ||
|
||
|
||
import Utils.Helpers | ||
|
||
|
||
type Log timestamp item = | ||
Log (List (timestamp, item)) | ||
|
||
|
||
empty : Log timestamp item | ||
empty = | ||
Log [] | ||
|
||
|
||
fromList : List (timestamp, item) -> Log timestamp item | ||
fromList log = | ||
Log log | ||
|
||
|
||
toList : Log timestamp item -> List (timestamp, item) | ||
toList (Log log) = | ||
log | ||
|
||
|
||
isEmpty : Log timestamp item -> Bool | ||
isEmpty (Log log) = | ||
List.isEmpty log | ||
|
||
|
||
append : (timestamp, item) -> Log timestamp item -> Log timestamp item | ||
append pair (Log log) = | ||
log ++ [pair] |> Log | ||
|
||
|
||
last : Log timestamp item -> Maybe (timestamp, item) | ||
last (Log log) = | ||
log |> Utils.Helpers.last | ||
|
||
|
||
mostRecentBeforeIndex : comparable -> Log comparable item -> Maybe item | ||
mostRecentBeforeIndex timestamp (Log log) = | ||
log | ||
|> List.filter (\(itemIdx, val) -> itemIdx <= timestamp) | ||
|> Utils.Helpers.last | ||
|> Maybe.map snd | ||
|
||
|
||
truncate : comparable -> Log comparable item -> Log comparable item | ||
truncate timestamp (Log log) = | ||
List.filter (\(idx, val) -> idx <= timestamp) log |> Log | ||
|
||
|
||
map : ((timestamp, item) -> (timestamp, b)) -> Log timestamp item -> Log timestamp b | ||
map func (Log log) = | ||
List.map func log |> Log | ||
|
||
|
||
filter : ((timestamp, item) -> Bool) -> Log timestamp item -> Log timestamp item | ||
filter predicate (Log log) = | ||
List.filter predicate log |> Log | ||
|
||
|
||
update | ||
: comparable | ||
-> ((comparable, item) -> item) | ||
-> Log comparable item | ||
-> Maybe (Log comparable item) | ||
update timestamp updater (Log log) = | ||
let | ||
(before, after) = | ||
List.partition (\(ts, _) -> ts < timestamp) log | ||
in | ||
case after of | ||
[] -> | ||
Nothing | ||
|
||
((ts, x)::xs) -> | ||
before ++ ((ts, updater (ts, x)) :: xs) | ||
|> Log | ||
|> Just |
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
Oops, something went wrong.