WorkOS.Cast (WorkOS SDK for Elixir v3.0.1)

Copy Markdown View Source

Nil-safe casting helpers used by generated from_map/1 and to_map/1 functions. Unexpected shapes pass through unchanged (lenient casting), so new or malformed API payloads never crash the SDK.

Summary

Functions

Dispatches a discriminated-union map to the caster for its discriminator value. Unknown discriminator values (and non-maps) pass through unchanged.

Drops nil-valued entries from a map.

Dumps a struct with fun; nil and already-plain values pass through.

Applies an enum cast/dump function; nil passes through.

Casts each element of a list with fun; non-lists pass through.

Casts each value of a map with fun; non-maps pass through.

Casts a nested map with fun; non-maps pass through.

Functions

discriminated(map, property, mapping)

@spec discriminated(term(), String.t(), %{optional(String.t()) => (map() -> term())}) ::
  term()

Dispatches a discriminated-union map to the caster for its discriminator value. Unknown discriminator values (and non-maps) pass through unchanged.

drop_nils(map)

@spec drop_nils(map()) :: map()

Drops nil-valued entries from a map.

dump_struct(value, fun)

@spec dump_struct(term(), (struct() -> map())) :: term()

Dumps a struct with fun; nil and already-plain values pass through.

enum(value, fun)

@spec enum(term(), (term() -> term())) :: term()

Applies an enum cast/dump function; nil passes through.

list(values, fun)

@spec list(term(), (term() -> term())) :: term()

Casts each element of a list with fun; non-lists pass through.

map_values(map, fun)

@spec map_values(term(), (term() -> term())) :: term()

Casts each value of a map with fun; non-maps pass through.

nested(value, fun)

@spec nested(term(), (map() -> term())) :: term()

Casts a nested map with fun; non-maps pass through.