Trail

A trail is the list of entries for a given key. It represents the history of changes for a given key.

type Trail =
  List Entry

A trail can be seen as a function sieve that filters the given log:

sieve : ID -> Log -> Maybe Trail

The algorithm:

  1. Let key be the identifier for the record to find.

  2. Let log be the full log to parse.

  3. Let result be an empty array.

  4. Foreach entry in the log:

    1. If the entry key equals the key, append entry to result.

      Otherwise, do nothing.

After all entries in the log have been inspected, the latest one stored in result is the record. If no entries were found for key, the trail doesn't exist in the Register.

For example, given a log:

log =
  [ Entry
     { number : 1
     , key: ID "A"
     ...
     }
  , Entry
     { number : 2
     , key: ID "B"
     ...
     }
  , Entry
     { number : 3
     , key: ID "Z"
     ...
     }
  , Entry
     { number : 4
     , key: ID "A"
     ...
     }
  , Entry
     { number : 5
     , key: ID "Z"
     ...
     }
  ]

The trail for element “A” is:

sieve (ID "A") log == Just Trail
                          [ Entry
                            { number : 1
                            , key: ID "A"
                            ...
                            }
                         , Entry
                            { number : 4
                            , key: ID "A"
                            ...
                            }
                         ]

© Crown copyright released under the Open Government Licence.