rosavox/source/helpers/list.php

40 lines
519 B
PHP
Raw Permalink Normal View History

<?php
namespace rosavox\helpers\list_;
/**
*/
function sequence(int $length) : array
{
return (($length <= 0) ? [] : \array_merge(sequence($length-1), [$length-1]));
}
/**
*/
function map(array $list, \Closure $function) : array
{
$result = [];
foreach ($list as $element)
{
\array_push($result, ($function)($element));
}
return $result;
}
/**
*/
function to_map(array $pairs) : array
{
$result = [];
foreach ($pairs as $pair)
{
$result[$pair['key']] = $pair['value'];
}
return $result;
}
?>