Predicator.Cast (predicator v9.0.0)

Copy Markdown View Source

The :: cast conversion matrix.

Implements every legal source-to-target conversion for the seven scalar ISA type names. The normative matrix is docs/isa.md section 5, under cast; ADR-0011 records why casting is an opcode rather than a lowering to call.

cast/2 is total over values and never raises or returns an error tuple: :undefined propagates, and a conversion that cannot produce a value of the target type also yields :undefined. This module is not part of the predicate surface - the only way an author reaches it is through :: - it is public for the same reason Predicator.Duration is: a value-layer helper worth documenting and testing on its own.

Summary

Functions

Converts value to the named type, or :undefined when it cannot.

The seven scalar ISA type names casts accept (docs/isa.md section 3).

Functions

cast(value, type_name)

@spec cast(term(), binary()) :: term()

Converts value to the named type, or :undefined when it cannot.

type_name must be one of type_names/0; passing anything else is a FunctionClauseError at this module's boundary, since the caller (the evaluator, guarded on the same list) never passes one.

type_names()

@spec type_names() :: [binary()]

The seven scalar ISA type names casts accept (docs/isa.md section 3).