apply
Types
Portable cross-runtime type tag; each constructor carries a value of that type.
Usage: case apply.classify(value) { VInt(n) -> ...; VString(s) -> ... }, for code
that runs on both targets.
Note: handle-like values (function / atom / tuple / local) are carried as
gleam/dynamic.Dynamic because the concrete handle types differ between Erlang and
JavaScript; for precise types such as Function / Atom / JsObj, use
erl.classify / js.classify on the matching runtime. Elements and keys of VList
/ VDict are Dynamic and can be read with gleam/dynamic decoders.
pub type Value {
VBool(v: Bool)
VInt(v: Int)
VFloat(v: Float)
VString(v: String)
VBitArray(v: BitArray)
VList(v: List(dynamic.Dynamic))
VDict(v: dict.Dict(dynamic.Dynamic, dynamic.Dynamic))
VNil
VTuple(v: dynamic.Dynamic)
VFunction(v: dynamic.Dynamic)
VAtom(v: dynamic.Dynamic)
VLocal(v: dynamic.Dynamic)
}
Constructors
-
VBool(v: Bool) -
VInt(v: Int) -
VFloat(v: Float) -
VString(v: String) -
VBitArray(v: BitArray) -
VList(v: List(dynamic.Dynamic)) -
VDict(v: dict.Dict(dynamic.Dynamic, dynamic.Dynamic)) -
VNil -
VTuple(v: dynamic.Dynamic) -
VFunction(v: dynamic.Dynamic) -
VAtom(v: dynamic.Dynamic) -
VLocal(v: dynamic.Dynamic)
Values
pub fn call(path: String, args: tupled_args) -> Result(a, String)
Cross-runtime entry point.
Dispatches to apply/erl or apply/js for the current platform and renders both
sides’ errors as a readable String. The success value is a generic a, asserted by
the caller for the use case, so callers need not care which runtime they are on.
Usage: call("Math.max", #(9, 2)) on js, call("erlang:length", #([1, 2, 3])) on erl.
Note: args must be a tuple; the success value is a generic a with no runtime type
checking; an unknown runtime returns Error("unsupported runtime: ...").
pub fn classify(value: any) -> Value
Cross-runtime classification: wraps boundary.identify and collapses the tag and
value into a portable Value.
Usage: apply.classify(value); value may come from call / try_catch / apply,
or be an element of a collection.
Note: no runtime checking — it trusts identify’s tag; handle-like values are
Dynamic, so for precise types use erl.classify / js.classify on the matching
runtime. In cross-target code, handle every constructor that can occur: VAtom only
appears on Erlang.