diff --git a/src/Functional/Each.php b/src/Functional/Each.php index 3720a725..8cda140b 100644 --- a/src/Functional/Each.php +++ b/src/Functional/Each.php @@ -17,9 +17,14 @@ * Iterates over a collection of elements, yielding each in turn to a callback function. Each invocation of $callback * is called with three arguments: (element, index, collection) * - * @param Traversable|array $collection - * @param callable $callback - * @return null + * @template K + * @template V + * + * @param iterable $collection + * @param callable(V,K,iterable):void $callback + * + * @return void + * * @no-named-arguments */ function each($collection, callable $callback) diff --git a/src/Functional/Every.php b/src/Functional/Every.php index e4d8ff62..c4c0ec12 100644 --- a/src/Functional/Every.php +++ b/src/Functional/Every.php @@ -17,9 +17,14 @@ * Returns true if every value in the collection passes the callback truthy test. Opposite of Functional\none(). * Callback arguments will be element, index, collection * - * @param Traversable|array $collection - * @param callable|null $callback + * @template K + * @template V + * + * @param iterable $collection + * @param callable(V,K,iterable):bool $callback + * * @return bool + * * @no-named-arguments */ function every($collection, callable $callback = null) diff --git a/src/Functional/Filter.php b/src/Functional/Filter.php index 46e09781..785449c0 100644 --- a/src/Functional/Filter.php +++ b/src/Functional/Filter.php @@ -16,9 +16,14 @@ /** * Alias of Functional\select() * - * @param Traversable|array $collection - * @param callable $callback - * @return array + * @template K + * @template V + * + * @param iterable $collection + * @param callable(V,K,iterable):bool $callback + * + * @return array + * * @no-named-arguments */ function filter($collection, callable $callback) diff --git a/src/Functional/First.php b/src/Functional/First.php index 87db945e..1e868a2a 100644 --- a/src/Functional/First.php +++ b/src/Functional/First.php @@ -18,9 +18,13 @@ * function returns as soon as it finds an acceptable element, and doesn't traverse the entire collection. Callback * arguments will be element, index, collection * - * @param Traversable|array $collection - * @param callable $callback - * @return mixed + * @template T + * + * @param iterable $collection + * @param null|callable(T):bool $callback + * + * @return ($collection is non-empty-array ? ($callback is null ? T : T|null) : T|null) + * * @no-named-arguments */ function first($collection, callable $callback = null) diff --git a/src/Functional/FlatMap.php b/src/Functional/FlatMap.php index 6a022f49..1a4f5d0f 100644 --- a/src/Functional/FlatMap.php +++ b/src/Functional/FlatMap.php @@ -24,9 +24,14 @@ * then flat_map(collection, callback) will return [1,2,3,[4]] * while flatten(map(collection, callback)) will return [1,2,3,4] * - * @param Traversable|array $collection - * @param callable $callback - * @return array + * @template K + * @template V + * @template V2 + * + * @param iterable $collection + * @param callable(V,K,iterable):(V2|iterable) $callback + * + * @return array * @no-named-arguments */ function flat_map($collection, callable $callback) diff --git a/src/Functional/Id.php b/src/Functional/Id.php index b7de88dc..a1153b2f 100644 --- a/src/Functional/Id.php +++ b/src/Functional/Id.php @@ -13,8 +13,12 @@ /** * Return value itself, without any modifications. * - * @param mixed $value - * @return mixed + * @template T + * + * @param T $value + * + * @return T + * * @no-named-arguments */ function id($value) diff --git a/src/Functional/Last.php b/src/Functional/Last.php index 8989f945..ccb0d9d2 100644 --- a/src/Functional/Last.php +++ b/src/Functional/Last.php @@ -17,9 +17,13 @@ * Looks through each element in the collection, returning the last one that passes a truthy test (callback). * Callback arguments will be element, index, collection * - * @param Traversable|array $collection - * @param callable $callback - * @return mixed + * @template T + * + * @param iterable $collection + * @param null|callable(T):bool $callback + * + * @return T|null + * * @no-named-arguments */ function last($collection, callable $callback = null) diff --git a/src/Functional/Map.php b/src/Functional/Map.php index 1bd577b3..2648f8af 100644 --- a/src/Functional/Map.php +++ b/src/Functional/Map.php @@ -17,9 +17,15 @@ * Produces a new array of elements by mapping each element in collection through a transformation function (callback). * Callback arguments will be element, index, collection * - * @param Traversable|array $collection - * @param callable $callback - * @return array + * @template K + * @template V + * @template V2 + * + * @param iterable $collection + * @param callable(V,K,iterable):V2 $callback + * + * @return array + * * @no-named-arguments */ function map($collection, callable $callback) diff --git a/src/Functional/ReduceLeft.php b/src/Functional/ReduceLeft.php index bce30c09..39b482dc 100644 --- a/src/Functional/ReduceLeft.php +++ b/src/Functional/ReduceLeft.php @@ -14,10 +14,16 @@ use Traversable; /** - * @param Traversable|array $collection - * @param callable $callback - * @param mixed $initial - * @return mixed + * @template K + * @template V + * @template V2 + * + * @param iterable $collection + * @param callable(V,K,iterable,V2):V2 $callback + * @param V2 $initial + * + * @return V2 + * * @no-named-arguments */ function reduce_left($collection, callable $callback, $initial = null) diff --git a/src/Functional/Reindex.php b/src/Functional/Reindex.php index ba6cbdf9..58f9addc 100644 --- a/src/Functional/Reindex.php +++ b/src/Functional/Reindex.php @@ -17,9 +17,15 @@ * Produces a new array of elements by assigning the values to keys generated by a transformation function (callback). * Callback arguments will be element, index, collection * - * @param Traversable|array $collection - * @param callable $callback - * @return array + * @template K + * @template V + * @template K2 + * + * @param iterable $collection + * @param callable(V,K,iterable):K2 $callback + * + * @return array + * * @no-named-arguments */ function reindex($collection, callable $callback) diff --git a/src/Functional/Select.php b/src/Functional/Select.php index 93420357..8a5523e7 100644 --- a/src/Functional/Select.php +++ b/src/Functional/Select.php @@ -17,9 +17,14 @@ * Looks through each element in the list, returning an array of all the elements that pass a truthy test (callback). * Opposite is Functional\reject(). Callback arguments will be element, index, collection * - * @param Traversable|array $collection - * @param callable|null $callback - * @return array + * @template K + * @template V + * + * @param iterable $collection + * @param callable(V,K,iterable):bool $callback + * + * @return array + * * @no-named-arguments */ function select($collection, callable $callback = null) diff --git a/src/Functional/Some.php b/src/Functional/Some.php index df27e0a8..ac38a706 100644 --- a/src/Functional/Some.php +++ b/src/Functional/Some.php @@ -17,9 +17,14 @@ * Returns true if some of the elements in the collection pass the callback truthy test. Short-circuits and stops * traversing the collection if a truthy element is found. Callback arguments will be value, index, collection * - * @param Traversable|array $collection - * @param callable|null $callback + * @template K + * @template V + * + * @param iterable $collection + * @param callable(V,K,iterable):bool $callback + * * @return bool + * * @no-named-arguments */ function some($collection, callable $callback = null) diff --git a/src/Functional/Sum.php b/src/Functional/Sum.php index e0f478b9..d1deed5e 100644 --- a/src/Functional/Sum.php +++ b/src/Functional/Sum.php @@ -16,9 +16,14 @@ /** * Takes a collection and returns the sum of the elements * - * @param Traversable|array $collection - * @param integer|float $initial - * @return integer|float + * @template K + * @template V of int|float + * + * @param iterable $collection + * @param V $initial + * + * @return V + * * @no-named-arguments */ function sum($collection, $initial = 0) diff --git a/src/Functional/Unique.php b/src/Functional/Unique.php index 656ac2be..1607a221 100644 --- a/src/Functional/Unique.php +++ b/src/Functional/Unique.php @@ -16,10 +16,15 @@ /** * Returns an array of unique elements * - * @param Traversable|array $collection - * @param callable $callback - * @param bool $strict - * @return array + * @template K + * @template V + * @template D + * + * @param iterable $collection + * @param null|callable(V,K,iterable):D $callback + * + * @return array + * * @no-named-arguments */ function unique($collection, callable $callback = null, $strict = true) diff --git a/src/Functional/With.php b/src/Functional/With.php index 9e4532e5..234c0647 100644 --- a/src/Functional/With.php +++ b/src/Functional/With.php @@ -15,11 +15,18 @@ /** * Invoke a callback on a value if the value is not null * - * @param mixed $value - * @param callable $callback + * @template V + * @template V2 + * @template V3 + * @template V4 + * + * @param V|null|callable():V4 $value + * @param callable(V):V2 $callback * @param bool $invokeValue Set to false to not invoke $value if it is a callable. Will be removed in 2.0 - * @param mixed $default The default value to return if $value is null - * @return mixed + * @param V3 $default The default value to return if $value is null + * + * @return ($value is null ? V3 : ($value is callable ? V4 : V2)) + * * @no-named-arguments */ function with($value, callable $callback, $invokeValue = true, $default = null)