# DataStructure

The DataStructure component provides typed immutable-like data structures, built on top of php-ds (opens new window).

# Map

The Map component is in charge of extending DS\Map (opens new window) functionality.

# Creating Map

Create a Map by passing named arguments of any type.

use Chevere\DataStructure\Map;

$map = new Map(foo: $foo, bar: $bar);

# Putting value

The withPut method is used to put a value to the Map at the given key.

$map = $map->withPut(foo: $foo, bar: $bar);

# Counting keys

The count method returns the number of keys mapped.

$count = $map->count(); // integer

# Accessing keys

The keys method is used to retrieve the map keys as an array.

$keys = $map->keys();

# Checking keys

The has method is used to check if the Map contains the given key(s).

$map->has('foo'); // true
$map->has('notFound'); // throws Throwable

# Asserting keys

The assertHas method is used to assert if the Map contains the given key(s).

$map->assertHas('foo'); // true
$map->assertHas('notFound'); // throws Throwable

# Get value

The get method is used to retrieve the Map value for the given key.

$getFoo = $map->get('foo'); // $foo
$getBar = $map->get('bar'); // $bar
Last Updated: 10/11/2022, 11:12:32 PM