Skip to content

Metadata values are stringly-typed — add helpers or polymorphic values #58

@tylerbutler

Description

@tylerbutler

Problem

Metadata is typed as List(#(String, String)), which forces every call site to manually convert non-string values:

birch.debug_m("Found test files", [
  #("count", int.to_string(list.length(files))),
])

This is verbose and repetitive, especially for Int, Float, and Bool values that appear frequently in structured logging.

Proposal

Option A — Helper function (minimal, non-breaking):

pub fn meta(key: String, value: a) -> #(String, String) {
  #(key, string.inspect(value))
}

// Usage:
birch.debug("Found files", [birch.meta("count", 42)])

Option B — Sum type for values (richer, breaking):

pub type MetadataValue {
  StringVal(String)
  IntVal(Int)
  FloatVal(Float)
  BoolVal(Bool)
}

pub type Metadata = List(#(String, MetadataValue))

This would let JSON and console handlers format values with proper types rather than everything being a string.

Option C — Both: add the meta helper now (non-breaking), consider the sum type for a future major version.

Context

In real-world usage (ccl_gleam test runner), nearly every metadata value requires an explicit int.to_string or similar conversion, adding noise to every log call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions