ACP.MaybeUndefined (agent_client_protocol v0.1.0)

Copy Markdown View Source

A three-state value type: :undefined, nil (null), or {:value, term}.

Similar to Option<T>, but distinguishes between a missing field (undefined) and an explicitly null field. This is important for partial update semantics where omitting a field means "don't change" and setting it to null means "clear".

JSON Serialization

  • :undefined → field is omitted from JSON output
  • nilnull
  • {:value, x} → the JSON encoding of x

Examples

iex> ACP.MaybeUndefined.is_undefined(:undefined)
true

iex> ACP.MaybeUndefined.is_undefined(nil)
false

iex> ACP.MaybeUndefined.is_undefined({:value, "hello"})
false

Summary

Functions

Converts to Option<Option<T>> equivalent: nil | {:some, nil} | {:some, value}.

Decodes a MaybeUndefined value from JSON deserialization. Call with :missing if the key was not present, or the value if it was.

Converts from a nested option back to MaybeUndefined.

Returns true if the value is null.

Returns true if the value is undefined.

Returns true if the value contains a value.

Maps a function over the value, preserving undefined/null.

Encodes a MaybeUndefined value for JSON serialization. Returns {:skip} for undefined (caller should omit the field), nil for null, or the value itself.

Updates a target value if the MaybeUndefined is not undefined.

Returns the inner value, or nil if undefined or null.

Types

t(value)

@type t(value) :: :undefined | nil | {:value, value}

Functions

as_opt_ref(arg1)

Converts to Option<Option<T>> equivalent: nil | {:some, nil} | {:some, value}.

from_json(v)

Decodes a MaybeUndefined value from JSON deserialization. Call with :missing if the key was not present, or the value if it was.

from_opt(arg1)

Converts from a nested option back to MaybeUndefined.

is_null(arg1)

Returns true if the value is null.

is_undefined(arg1)

Returns true if the value is undefined.

is_value(arg1)

Returns true if the value contains a value.

map_value(arg1, fun)

Maps a function over the value, preserving undefined/null.

to_json(arg1)

Encodes a MaybeUndefined value for JSON serialization. Returns {:skip} for undefined (caller should omit the field), nil for null, or the value itself.

update_to(arg1, current)

Updates a target value if the MaybeUndefined is not undefined.

  • :undefined → returns the current value unchanged
  • nil → returns nil (clear)
  • {:value, v} → returns v (set)

value(arg1)

Returns the inner value, or nil if undefined or null.