Helpers

Brand

Small branding helpers for constructor-first validated values.

Brands let the library distinguish validated carried values from raw user input without changing their runtime representation. Constructors built with this module are always explicit and non-throwing.

This matters in game code whenever one plain structural shape is too weak to express a guarantee. Helpers like Vector2, Size2, Scalar, and Aabb all build on this module so validated values can move through the ECS without losing the fact that they were checked once already.

Examples

// Create a domain-specific constructor that only accepts valid ports.
const Port = Brand.refine((raw: number) =>
  raw > 0
    ? Result.success(raw as Brand.Branded<number, "Port">)
    : Result.failure({ tag: "InvalidPort", value: raw })
)

Constructors

Helpers that build explicit non-throwing validators from raw input checks.

refine

Source

Builds one explicit non-throwing constructor from a validation function.

all

Source

Combines two constructors that validate the same carried value.

The returned constructor succeeds only when both validations succeed.