Skip to content

feat: add Prefix, a code cut off after a segment - #74

Merged
Adeniyikayodee merged 6 commits into
mainfrom
feat/prefix
Oct 10, 2026
Merged

Adeniyikayodee merged 6 commits into
mainfrom
feat/prefix

Conversation

@Adeniyikayodee

Copy link
Copy Markdown
Owner

A prefix is a postcode cut off after one of its segments, such as the district EK-01-A03. It names every code that starts with it, so it is the value to group or select records by: state, LGA, district, or area. Until now the libraries only produced a prefix as a string.

  • Spec first: spec/vectors.json gains cases for parsing a prefix, for which codes it contains, and for its parent. All four languages run them.
  • The same surface in each language: parse a prefix in any style, read through (its last segment), take its parent, ask whether it contains a code, and cut a code down with truncate. A whole code is the narrowest prefix.
  • truncate as the name: it mirrors date_trunc in SQL and dt.truncate in dataframes, which is how the people who will group by place already think. The existing prefix() keeps returning a string, since changing it would quietly break comparisons in Python and JavaScript.
  • One new error: a prefix must end where a segment does, after 2, 4, 7, 9, or 11 characters. Anything else is a prefix length error with the same message everywhere.

Nothing is released by this. Java will need 0.3.0 when it is, because the new error is a case on the sealed ParseError, which breaks an exhaustive switch in a caller's code. Rust's enum is non-exhaustive, so the crate does not break.

@Adeniyikayodee
Adeniyikayodee merged commit 530147b into main Oct 10, 2026
16 checks passed
@Adeniyikayodee
Adeniyikayodee deleted the feat/prefix branch October 10, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant