Module map_ops

Module map_ops 

Source
Expand description

Map operations for Seq

Dictionary/hash map operations with O(1) lookup. Maps use hashable keys (Int, String, Bool) and can store any Value.

§Examples

# Create empty map and add entries
make-map "name" "Alice" map-set "age" 30 map-set

# Get value by key
my-map "name" map-get  # -> "Alice"

# Check if key exists
my-map "email" map-has?  # -> 0 (false)

# Get keys/values as lists
my-map map-keys    # -> ["name", "age"]
my-map map-values  # -> ["Alice", 30]

§Panic Behavior

  • Operations panic on invalid key types (Float, Variant, Quotation, etc.)
  • map-get panics if key not found (use map-get-safe for error handling)
  • Type errors (e.g., calling map operations on non-Map values) cause panics

§Performance Notes

  • Operations use functional style: map-set and map-remove return new maps
  • Each mutation clones the underlying HashMap (O(n) for n entries)
  • For small maps (<100 entries), this is typically fast enough
  • Key/value iteration order is not guaranteed (HashMap iteration order)

Re-exports§

pub use patch_seq_make_map as make_map;
pub use patch_seq_map_empty as map_empty;
pub use patch_seq_map_get as map_get;
pub use patch_seq_map_get_safe as map_get_safe;
pub use patch_seq_map_has as map_has;
pub use patch_seq_map_keys as map_keys;
pub use patch_seq_map_remove as map_remove;
pub use patch_seq_map_set as map_set;
pub use patch_seq_map_size as map_size;
pub use patch_seq_map_values as map_values;

Functions§

patch_seq_make_map
Create an empty map
patch_seq_map_empty
Check if the map is empty
patch_seq_map_get
Get a value from the map by key
patch_seq_map_get_safe
Get a value from the map by key, with error handling
patch_seq_map_has
Check if a key exists in the map
patch_seq_map_keys
Get all keys from the map as a list
patch_seq_map_remove
Remove a key from the map (functional style)
patch_seq_map_set
Set a key-value pair in the map (functional style)
patch_seq_map_size
Get the number of entries in the map
patch_seq_map_values
Get all values from the map as a list