Module
pooka/dynamic
src/pooka/dynamic.pookaA foreign value arrives without a trustworthy label. Keep it behind checked readers rather than calling an unchecked cast a type. Primitive readers distinguish integers from floats and UTF-8 text from bytes. Lists must be proper; map fields use UTF-8 binary keys and tuple indexes start at zero. This is an Erlang boundary, not a general serializer for Pooka classes.
assert dynamic.from(42).as_int() == Some(42)
assert dynamic.from("42").as_int() == None
API reference
class Dynamic
Checked capabilities over one captured BEAM value. No raw term is exposed.
new(
int: fn() -> Option(Int),
float: fn() -> Option(Float),
string: fn() -> Option(String),
bool: fn() -> Option(Bool),
bits: fn() -> Option(BitArray),
list: fn() -> Option(List(Dynamic)),
field: fn(String) -> Option(Dynamic),
element: fn(Int) -> Option(Dynamic),
kind: fn() -> String
)
fn(fn() -> Option(Int), fn() -> Option(Float), fn() -> Option(String), fn() -> Option(Bool), fn() -> Option(BitArray), fn() -> Option(List(pooka/dynamic.Dynamic)), fn(String) -> Option(pooka/dynamic.Dynamic), fn(Int) -> Option(pooka/dynamic.Dynamic), fn() -> String) -> pooka/dynamic.Dynamicas_int() -> Option(Int)
fn() -> Option(Int)Read int only when the captured runtime shape permits it.
as_float() -> Option(Float)
fn() -> Option(Float)Read float only when the captured runtime shape permits it.
as_string() -> Option(String)
fn() -> Option(String)Read string only when the captured runtime shape permits it.
as_bool() -> Option(Bool)
fn() -> Option(Bool)Read bool only when the captured runtime shape permits it.
as_bits() -> Option(BitArray)
fn() -> Option(BitArray)Read bits only when the captured runtime shape permits it.
as_list() -> Option(List(Dynamic))
fn() -> Option(List(pooka/dynamic.Dynamic))Read list only when the captured runtime shape permits it.
field(name: String) -> Option(Dynamic)
fn(String) -> Option(pooka/dynamic.Dynamic)Read field only when the captured runtime shape permits it.
element(index: Int) -> Option(Dynamic)
fn(Int) -> Option(pooka/dynamic.Dynamic)Read element only when the captured runtime shape permits it.
kind() -> String
fn() -> StringRead kind only when the captured runtime shape permits it.
from(value: a) -> Dynamic
fn(a) -> pooka/dynamic.DynamicCapture any value through checked readers. It gains no new static claims.
from_pairs(pairs: List(#(String, a))) -> Dynamic
fn(List(#(String, a))) -> pooka/dynamic.DynamicConstruct a foreign-style binary-key map for decoding. Last duplicate wins.