Summarise an Event Log by Kind
Write the code, see it run, pass the checks.
The problem
- medium
- Code
An app logs events told apart by kind: click (with x and y), view (with a path) and error (with a message). Export the AppEvent type, summarise(events), which counts the events of each kind and includes every kind, with 0 for kinds that didn't happen, and latestOf(events, kind), which returns the last event of that kind or undefined. Type summarise's result as a record with exactly one count per kind, built from AppEvent, and type latestOf so it returns that kind's own event type and rejects kinds that don't exist.
Your code must pass
- Counts each kind
- Counts zero for kinds that didn't happen
- Finds the latest event of a kind
- Has no type errors
- The summary has one count per kind
- latestOf returns that kind's event
- Rejects an unknown kind