phptools-docs
phptools-docs copied to clipboard
generic issue
<?php
/**
* @template Tkey
* @template TValue
*/
class Collection
{
/**
* @template TMap
* @param callable(TValue, Tkey): TMap $callable
* @return static<TKey, TMap>
*/
public function map($callable)
{
}
}
/**
* @template TKey
* @template TValue
*
* @param iterable<TKey, TValue>|array<TValue> $iter
* @return Collection<TKey, TValue>
*/
function collection($iter)
{
}
$c = collection([1, 2, 3]);
$c1 = $c->map(function ($value, $key): string {
// $value should be int
return 'string';
}); // $c1 should be Collection<TKey, string> instead Collection<TKey, int>