for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* Copyright (C) 2022 Sebastian Böttger <[email protected]>
* You may use, distribute and modify this code under the
* terms of the MIT license.
*
* You should have received a copy of the MIT license with
* this file. If not, please visit: https://opensource.org/licenses/mit-license.php
*/
namespace Seboettg\Collection\Map;
use InvalidArgumentException;
final class Functions
{
/**
* @return MapInterface
public static final function emptyMap(): MapInterface
final
return new class() implements MapInterface {
private $array = [];
$array
use MapTrait;
};
}
* @param array<Pair> ...$pairs
public final static function mapOf(...$pairs): MapInterface
$map = emptyMap();
$map->setArray(array_combine(
array_map(fn (Pair $pair) => $pair->getKey(), $pairs), //keys
array_map(fn (Pair $pair) => $pair->getValue(), $pairs) //values
));
return $map;
* @param scalar $key
* @param mixed $value
* @return Pair
public final static function pair($key, $value): Pair
return new Pair($key, $value);
function emptyMap(): MapInterface
return Functions::emptyMap();
function mapOf(...$pairs): MapInterface
return Functions::mapOf(...$pairs);
function pair($key, $value): Pair
return Functions::pair($key, $value);