phptools-docs icon indicating copy to clipboard operation
phptools-docs copied to clipboard

generic issue

Open ging-dev opened this issue 2 months ago • 2 comments

<?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>

ging-dev avatar May 07 '24 16:05 ging-dev