Skip to content

Instantly share code, notes, and snippets.

@flq flq/BitempTests.fs
Last active Dec 16, 2016

Embed
What would you like to do?
Bitemporal code samples
module BitempTests
type TimePoint<'S> = {
recorded : int;
actual : int;
state : 'S;
}
type HistoryEntry<'S> = {
time : int;
state : 'S;
}
type History<'S> = HistoryEntry<'S> list
let chain1 = [
{ recorded = 1; actual = 1; state = "First" };
{ recorded = 2; actual = 5; state = "Second" };
{ recorded = 3; actual = 7; state = "Third" };
]
let chain2 = [
{ recorded = 1; actual = 1; state = "First" };
{ recorded = 2; actual = 7; state = "Second" };
{ recorded = 3; actual = 5; state = "Third" };
]
let (|MustBeConsidered|CanBeIgnored|) (reference, newTime) =
if (newTime.actual <= reference.time) then MustBeConsidered else CanBeIgnored
let foldHistory<'S> history timePoint =
let newPoint = fun () -> { time = timePoint.actual; state = timePoint.state }
match history with
| [] -> newPoint() :: history
| hstEntry::rest -> match (hstEntry, timePoint) with
| MustBeConsidered -> newPoint() :: history
| CanBeIgnored -> history
[<EntryPoint>]
let main argv =
let recorded = int argv.[0]
let history =
chain2
|> List.sortByDescending (fun tp -> tp.recorded)
|> List.skipWhile (fun tp -> tp.recorded > recorded)
|> List.fold foldHistory []
|> List.iter (printfn "%A")
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.