# `PtcRunner.Lisp.Runtime.MapOps`
[🔗](https://github.com/andreasronge/ptc_runner/blob/main/lib/ptc_runner/lisp/runtime/map_ops.ex#L1)

Map operations for PTC-Lisp runtime.

Provides get, assoc, update, merge, and other map manipulation functions.

# `array_map`

Creates a map from alternating key-value pairs.

Equivalent to Clojure's `array-map`. PTC-Lisp currently uses the same
unordered runtime map representation as `hash-map`.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.array_map([])
    %{}

    iex> PtcRunner.Lisp.Runtime.MapOps.array_map([:a, 1, :b, 2])
    %{a: 1, b: 2}

# `assoc`

# `assoc_in`

# `assoc_variadic`

Associate key-value pairs with a map.

Supports both standard 3-arg form and variadic form with multiple pairs:
- (assoc m k v)
- (assoc m k1 v1 k2 v2 k3 v3)

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.assoc_variadic([%{a: 1}, :b, 2])
    %{a: 1, b: 2}

    iex> PtcRunner.Lisp.Runtime.MapOps.assoc_variadic([%{}, :a, 1, :b, 2, :c, 3])
    %{a: 1, b: 2, c: 3}

# `disj`

Removes items from a set. Returns nil for nil input.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.disj(MapSet.new([1, 2, 3]), 2)
    MapSet.new([1, 3])

# `dissoc`

# `dissoc_variadic`

Remove keys from a map.

Supports both 2-arg form and variadic form with multiple keys:
- (dissoc m k)
- (dissoc m k1 k2 k3)

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.dissoc_variadic([%{a: 1, b: 2}, :a])
    %{b: 2}

    iex> PtcRunner.Lisp.Runtime.MapOps.dissoc_variadic([%{a: 1, b: 2, c: 3}, :a, :c])
    %{b: 2}

# `entries`

Convert map to a list of [key, value] pairs, sorted by key.

# `get`

# `get`

# `get_in`

# `get_in`

# `hash_map`

Creates a map from alternating key-value pairs.

Equivalent to Clojure's `hash-map`. Requires an even number of arguments.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.hash_map([])
    %{}

    iex> PtcRunner.Lisp.Runtime.MapOps.hash_map([:a, 1, :b, 2])
    %{a: 1, b: 2}

# `key`

Returns the key from a map entry (2-element vector).

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.key([:a, 1])
    :a

# `keys`

# `merge`

# `merge_variadic`

# `merge_with_variadic`

Merges maps using a combining function for duplicate keys.
Nil maps are treated as empty maps.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.merge_with_variadic([fn a, b -> a + b end, %{a: 1}, %{a: 2, b: 3}])
    %{a: 3, b: 3}

# `reduce_kv`

Reduces a map with a function that receives accumulator, key, and value.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.reduce_kv(fn acc, k, v -> acc + v end, 0, %{a: 1, b: 2})
    3

# `select_keys`

# `update`

# `update_in`

# `update_in_variadic`

Update a nested value in a map by applying a function.

Supports Clojure-style extra arguments that are passed to the function:
- (update-in m path f) - calls (f old-val)
- (update-in m path f arg1) - calls (f old-val arg1)

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.update_in_variadic([%{a: %{b: 1}}, [:a, :b], &Kernel.+/2, 5])
    %{a: %{b: 6}}

# `update_keys`

Applies a function to each key in a map, returning a new map.
If key collisions occur, the retained value is unspecified.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.update_keys(%{a: 1, b: 2}, &Atom.to_string/1)
    %{"a" => 1, "b" => 2}

    iex> PtcRunner.Lisp.Runtime.MapOps.update_keys(%{}, &Atom.to_string/1)
    %{}

# `update_vals`

Apply a function to each value in a map, returning a new map with the same keys.
Matches Clojure 1.11's update-vals signature: `(update-vals m f)`

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.update_vals(%{a: [1, 2], b: [3]}, &length/1)
    %{a: 2, b: 1}

    iex> PtcRunner.Lisp.Runtime.MapOps.update_vals(%{}, &length/1)
    %{}

# `update_variadic`

Update a value in a map by applying a function.

Supports Clojure-style extra arguments that are passed to the function:
- (update m k f) - calls (f old-val)
- (update m k f arg1) - calls (f old-val arg1)
- (update m k f arg1 arg2) - calls (f old-val arg1 arg2)

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.update_variadic([%{n: 1}, :n, &Kernel.+/2, 5])
    %{n: 6}

    iex> PtcRunner.Lisp.Runtime.MapOps.update_variadic([%{n: nil}, :n, &PtcRunner.Lisp.Runtime.Predicates.fnil(&Kernel.+/2, 0), 5])
    %{n: 5}

# `val`

Returns the value from a map entry (2-element vector).

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.val([:a, 1])
    1

# `vals`

# `zipmap`

Creates a map from a seq of keys and a seq of values.
Truncates to the shorter input. Accepts any seqable inputs.

## Examples

    iex> PtcRunner.Lisp.Runtime.MapOps.zipmap([:a, :b, :c], [1, 2, 3])
    %{a: 1, b: 2, c: 3}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
