View Source cure_typeclass_dispatch (cure v0.7.0)

Summary

Functions

Call a typeclass method directly with a receiver value Useful when you already know the method implementation

Dispatch a typeclass method call with runtime type inference This is the main entry point for method dispatch.

Fast-path dispatch using persistent_term cache Returns {error, cache_miss} if not in cache

Infer Cure type from Erlang runtime value This allows dispatch to work with native Erlang values

Invalidate cached method for a typeclass/type combination

Pre-warm cache for a specific typeclass/type combination Useful for hot paths where we want to ensure first call is fast

Functions

call_method(_, Receiver, Args)

-spec call_method({module(), atom(), arity()}, term(), [term()]) -> term().

Call a typeclass method directly with a receiver value Useful when you already know the method implementation

dispatch(Typeclass, Method, Receiver, Args)

-spec dispatch(atom(), atom(), term(), [term()]) -> term() | {error, term()}.

Dispatch a typeclass method call with runtime type inference This is the main entry point for method dispatch.

dispatch_cached(Typeclass, Method, ReceiverType, Args)

-spec dispatch_cached(atom(), atom(), term(), [term()]) -> term() | {error, cache_miss}.

Fast-path dispatch using persistent_term cache Returns {error, cache_miss} if not in cache

infer_runtime_type(Value)

-spec infer_runtime_type(term()) -> term().

Infer Cure type from Erlang runtime value This allows dispatch to work with native Erlang values

invalidate_cache(Typeclass, Type)

-spec invalidate_cache(atom(), term()) -> ok.

Invalidate cached method for a typeclass/type combination

warm_cache(Typeclass, Type)

-spec warm_cache(atom(), term()) -> ok | {error, term()}.

Pre-warm cache for a specific typeclass/type combination Useful for hot paths where we want to ensure first call is fast