<commit_before>---
id: trail-def
title: Trail
url: /glossary/trail
---

A **trail** is the list of [entries](/glossary/entry) for a given key. It
represents the history of changes for a given key.

```elm
type Trail =
  List Entry
```

A trail can be seen as a function `filterBy` that derives from a given
[log](/glossary/log):

```elm
filterBy : ID -> Log -> Maybe Trail
```

Similar to the [snapshot](/glossary/snapshot), there is a function to get the
[record](/glossary/record) from the **trail**:

```elm
record : Trail -> Entry
```

![](./data-model/data-model-trail.svg)

***
**EXAMPLE:**

For example, given a log:

```elm
log =
  [ Entry
     { number : 1
     , key: ID "A"
     ...
     }<commit_msg>content(glossary): Define algorithms for trail<commit_after>---
id: trail-def
title: Trail
url: /glossary/trail
---

A **trail** is the list of [entries](/glossary/entry) for a given key. It
represents the history of changes for a given key.

```elm
type Trail =
  List Entry
```

A trail can be seen as a function `filterBy` that derives from a given
[log](/glossary/log):

```elm
filterBy : ID -> Log -> Maybe Trail
```

The algorithm:

1. Let _key_ be the identifier for the record to find.
1. Let _log_ be the full log to parse.
1. Let _result_ be an empty array.
1. 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.

Similar to the [snapshot](/glossary/snapshot), there is a function to get the
[record](/glossary/record) from the **trail**:

```elm
record : Trail -> Entry
```

The algorithm:

1. Let _trail_ be the full list of entries for a key.
1. Let _result_ be null.
1. Foreach _entry_ in the _log_:
    1. If the _entry_ id is bigger than the one stored in _result_, set
       _entry_ in _result_.

       Otherwise, do nothing.

After all entries in the log have been inspected, the latest one stored in
_result_ is the record.

![](./data-model/data-model-trail.svg)

***
**EXAMPLE:**

For example, given a log:

```elm
log =
  [ Entry
     { number : 1
     , key: ID "A"
     ...
     }
{'fraction_non_alphanumeric': 0.1193505923650724, 'fraction_numerical': 0.004826678367705134, 'mean_word_length': 3.1379310344827585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4496236', 'n_tokens_mistral': 782, 'n_tokens_neox': 751, 'n_words': 325}