diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..377d3d47 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ +# Changelog + +## 2.0.0 + +### Arr + +* **BC** - removed `Psl\Arr` component. + +### Type + +* **BC** - removed `Type\is_array`, `Type\is_arraykey`, `Type\is_bool`, `Type\is_callable`, `Type\is_float`, `Type\is_instanceof`, `Type\is_int`, `Type\is_iterable`, `Type\is_null`, `Type\is_numeric`, `Type\is_object`, `Type\is_resource`, `Type\is_scalar`, and `Type\is_string` functions ( use `TypeInterface::matches($value)` instead ). + +### Iter + +* **BC** - removed `Iter\chain`, `Iter\chunk`, `Iter\chunk_with_keys`, `Iter\diff_by_key`, `Iter\drop`, `Iter\drop_while`, `Iter\enumerate`, `Iter\filter`, `Iter\filter_keys`, `Iter\filter_nulls`, `Iter\filter_with_key`, `Iter\flat_map`, `Iter\flatten`, `Iter\flip`, `Iter\from_entries`, `Iter\from_keys`, `Iter\keys`, `Iter\map`, `Iter\map_keys`, `Iter\map_with_key`, `Iter\merge`, `Iter\product`, `Iter\pull`, `Iter\pull_with_key`, `Iter\range`, `Iter\reductions`, `Iter\reindex`, `Iter\repeat`, `Iter\reproduce`, `Iter\reverse`, `Iter\slice`, `Iter\take`, `Iter\take_while`, `Iter\to_array`, `Iter\to_array_with_keys`, `Iter\values`, and `Iter\zip` functions. +* **BC** - signature of `Iter\reduce_keys` function changed from `reduce_keys(iterable $iterable, (callable(?Ts, Tk): Ts) $function, Ts|null $initial = null): Ts|null` to `reduce_keys(iterable $iterable, (callable(Ts, Tk): Ts) $function, Ts $initial): Ts`. +* **BC** - signature of `Iter\reduce_with_keys` function changed from `reduce_with_keys(iterable $iterable, (callable(?Ts, Tk, Tv): Ts) $function, Ts|null $initial = null): Ts|null` to `reduce_with_keys(iterable $iterable, (callable(Ts, Tk, Tv): Ts) $function, Ts $initial): Ts`. diff --git a/docs/README.md b/docs/README.md index 0908cdc2..f739fef1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,6 @@ # Components API - [Psl](./component/psl.md) -- [Psl\Arr](./component/arr.md) - [Psl\Class](./component/class.md) - [Psl\Collection](./component/collection.md) - [Psl\DataStructure](./component/data-structure.md) diff --git a/docs/component/arr.md b/docs/component/arr.md deleted file mode 100644 index f10323b9..00000000 --- a/docs/component/arr.md +++ /dev/null @@ -1,61 +0,0 @@ - - -[*index](./../README.md) - ---- - -### `Psl\Arr` Component - -#### `Functions` - -- [at](./../../src/Psl/Arr/at.php#L27) ( deprecated ) -- [concat](./../../src/Psl/Arr/concat.php#L22) ( deprecated ) -- [contains](./../../src/Psl/Arr/contains.php#L24) ( deprecated ) -- [contains_key](./../../src/Psl/Arr/contains_key.php#L25) ( deprecated ) -- [count](./../../src/Psl/Arr/count.php#L36) ( deprecated ) -- [count_values](./../../src/Psl/Arr/count_values.php#L22) ( deprecated ) -- [drop](./../../src/Psl/Arr/drop.php#L31) ( deprecated ) -- [drop_while](./../../src/Psl/Arr/drop_while.php#L31) ( deprecated ) -- [equal](./../../src/Psl/Arr/equal.php#L22) ( deprecated ) -- [fill](./../../src/Psl/Arr/fill.php#L25) ( deprecated ) -- [filter](./../../src/Psl/Arr/filter.php#L34) ( deprecated ) -- [filter_keys](./../../src/Psl/Arr/filter_keys.php#L34) ( deprecated ) -- [filter_nulls](./../../src/Psl/Arr/filter_nulls.php#L25) ( deprecated ) -- [filter_with_key](./../../src/Psl/Arr/filter_with_key.php#L37) ( deprecated ) -- [first](./../../src/Psl/Arr/first.php#L24) ( deprecated ) -- [first_key](./../../src/Psl/Arr/first_key.php#L25) ( deprecated ) -- [firstx](./../../src/Psl/Arr/firstx.php#L28) ( deprecated ) -- [flat_map](./../../src/Psl/Arr/flat_map.php#L22) ( deprecated ) -- [flatten](./../../src/Psl/Arr/flatten.php#L33) ( deprecated ) -- [flip](./../../src/Psl/Arr/flip.php#L28) ( deprecated ) -- [group_by](./../../src/Psl/Arr/group_by.php#L43) ( deprecated ) -- [idx](./../../src/Psl/Arr/idx.php#L35) ( deprecated ) -- [keys](./../../src/Psl/Arr/keys.php#L22) ( deprecated ) -- [last](./../../src/Psl/Arr/last.php#L24) ( deprecated ) -- [last_key](./../../src/Psl/Arr/last_key.php#L26) ( deprecated ) -- [lastx](./../../src/Psl/Arr/lastx.php#L28) ( deprecated ) -- [map](./../../src/Psl/Arr/map.php#L34) ( deprecated ) -- [map_keys](./../../src/Psl/Arr/map_keys.php#L34) ( deprecated ) -- [map_with_key](./../../src/Psl/Arr/map_with_key.php#L34) ( deprecated ) -- [merge](./../../src/Psl/Arr/merge.php#L34) ( deprecated ) -- [partition](./../../src/Psl/Arr/partition.php#L22) ( deprecated ) -- [random](./../../src/Psl/Arr/random.php#L25) ( deprecated ) -- [select_keys](./../../src/Psl/Arr/select_keys.php#L25) ( deprecated ) -- [shuffle](./../../src/Psl/Arr/shuffle.php#L30) ( deprecated ) -- [slice](./../../src/Psl/Arr/slice.php#L35) ( deprecated ) -- [sort](./../../src/Psl/Arr/sort.php#L24) ( deprecated ) -- [sort_by](./../../src/Psl/Arr/sort_by.php#L27) ( deprecated ) -- [sort_by_key](./../../src/Psl/Arr/sort_by_key.php#L25) ( deprecated ) -- [sort_with_keys](./../../src/Psl/Arr/sort_with_keys.php#L25) ( deprecated ) -- [sort_with_keys_by](./../../src/Psl/Arr/sort_with_keys_by.php#L29) ( deprecated ) -- [take](./../../src/Psl/Arr/take.php#L25) ( deprecated ) -- [take_while](./../../src/Psl/Arr/take_while.php#L31) ( deprecated ) -- [unique](./../../src/Psl/Arr/unique.php#L22) ( deprecated ) -- [unique_by](./../../src/Psl/Arr/unique_by.php#L26) ( deprecated ) -- [values](./../../src/Psl/Arr/values.php#L25) ( deprecated ) - - diff --git a/docs/component/iter.md b/docs/component/iter.md index 4582f76e..7b3afa5f 100644 --- a/docs/component/iter.md +++ b/docs/component/iter.md @@ -15,58 +15,21 @@ - [all](./../../src/Psl/Iter/all.php#L28) - [any](./../../src/Psl/Iter/any.php#L28) - [apply](./../../src/Psl/Iter/apply.php#L27) -- [chain](./../../src/Psl/Iter/chain.php#L31) ( deprecated ) -- [chunk](./../../src/Psl/Iter/chunk.php#L33) ( deprecated ) -- [chunk_with_keys](./../../src/Psl/Iter/chunk_with_keys.php#L30) ( deprecated ) - [contains](./../../src/Psl/Iter/contains.php#L27) - [contains_key](./../../src/Psl/Iter/contains_key.php#L16) - [count](./../../src/Psl/Iter/count.php#L29) -- [diff_by_key](./../../src/Psl/Iter/diff_by_key.php#L23) ( deprecated ) -- [drop](./../../src/Psl/Iter/drop.php#L31) ( deprecated ) -- [drop_while](./../../src/Psl/Iter/drop_while.php#L31) ( deprecated ) -- [enumerate](./../../src/Psl/Iter/enumerate.php#L23) ( deprecated ) -- [filter](./../../src/Psl/Iter/filter.php#L34) ( deprecated ) -- [filter_keys](./../../src/Psl/Iter/filter_keys.php#L36) ( deprecated ) -- [filter_nulls](./../../src/Psl/Iter/filter_nulls.php#L26) ( deprecated ) -- [filter_with_key](./../../src/Psl/Iter/filter_with_key.php#L39) ( deprecated ) - [first](./../../src/Psl/Iter/first.php#L27) - [first_key](./../../src/Psl/Iter/first_key.php#L30) -- [flat_map](./../../src/Psl/Iter/flat_map.php#L22) ( deprecated ) -- [flatten](./../../src/Psl/Iter/flatten.php#L24) ( deprecated ) -- [flip](./../../src/Psl/Iter/flip.php#L27) ( deprecated ) -- [from_entries](./../../src/Psl/Iter/from_entries.php#L24) ( deprecated ) -- [from_keys](./../../src/Psl/Iter/from_keys.php#L25) ( deprecated ) - [is_empty](./../../src/Psl/Iter/is_empty.php#L12) -- [keys](./../../src/Psl/Iter/keys.php#L28) ( deprecated ) - [last](./../../src/Psl/Iter/last.php#L17) - [last_key](./../../src/Psl/Iter/last_key.php#L17) -- [map](./../../src/Psl/Iter/map.php#L35) ( deprecated ) -- [map_keys](./../../src/Psl/Iter/map_keys.php#L35) ( deprecated ) -- [map_with_key](./../../src/Psl/Iter/map_with_key.php#L33) ( deprecated ) -- [merge](./../../src/Psl/Iter/merge.php#L32) ( deprecated ) -- [product](./../../src/Psl/Iter/product.php#L34) ( deprecated ) -- [pull](./../../src/Psl/Iter/pull.php#L40) ( deprecated ) -- [pull_with_key](./../../src/Psl/Iter/pull_with_key.php#L41) ( deprecated ) - [random](./../../src/Psl/Iter/random.php#L23) -- [range](./../../src/Psl/Iter/range.php#L45) ( deprecated ) - [reduce](./../../src/Psl/Iter/reduce.php#L32) - [reduce_keys](./../../src/Psl/Iter/reduce_keys.php#L33) - [reduce_with_keys](./../../src/Psl/Iter/reduce_with_keys.php#L40) -- [reductions](./../../src/Psl/Iter/reductions.php#L33) ( deprecated ) -- [reindex](./../../src/Psl/Iter/reindex.php#L43) ( deprecated ) -- [repeat](./../../src/Psl/Iter/repeat.php#L36) ( deprecated ) -- [reproduce](./../../src/Psl/Iter/reproduce.php#L33) ( deprecated ) -- [reverse](./../../src/Psl/Iter/reverse.php#L26) ( deprecated ) - [rewindable](./../../src/Psl/Iter/rewindable.php#L20) - [search](./../../src/Psl/Iter/search.php#L26) -- [slice](./../../src/Psl/Iter/slice.php#L36) ( deprecated ) -- [take](./../../src/Psl/Iter/take.php#L25) ( deprecated ) -- [take_while](./../../src/Psl/Iter/take_while.php#L32) ( deprecated ) -- [to_array](./../../src/Psl/Iter/to_array.php#L21) ( deprecated ) -- [to_array_with_keys](./../../src/Psl/Iter/to_array_with_keys.php#L22) ( deprecated ) - [to_iterator](./../../src/Psl/Iter/to_iterator.php#L19) -- [values](./../../src/Psl/Iter/values.php#L32) ( deprecated ) -- [zip](./../../src/Psl/Iter/zip.php#L38) ( deprecated ) #### `Classes` diff --git a/docs/component/type.md b/docs/component/type.md index 0a962ee5..fd9d0016 100644 --- a/docs/component/type.md +++ b/docs/component/type.md @@ -18,21 +18,7 @@ - [float](./../../src/Psl/Type/float.php#L10) - [int](./../../src/Psl/Type/int.php#L10) - [intersection](./../../src/Psl/Type/intersection.php#L22) -- [is_array](./../../src/Psl/Type/is_array.php#L18) ( deprecated ) -- [is_arraykey](./../../src/Psl/Type/is_arraykey.php#L16) ( deprecated ) -- [is_bool](./../../src/Psl/Type/is_bool.php#L18) ( deprecated ) -- [is_callable](./../../src/Psl/Type/is_callable.php#L16) -- [is_float](./../../src/Psl/Type/is_float.php#L18) ( deprecated ) -- [is_instanceof](./../../src/Psl/Type/is_instanceof.php#L22) ( deprecated ) -- [is_int](./../../src/Psl/Type/is_int.php#L18) ( deprecated ) -- [is_iterable](./../../src/Psl/Type/is_iterable.php#L18) ( deprecated ) - [is_nan](./../../src/Psl/Type/is_nan.php#L14) -- [is_null](./../../src/Psl/Type/is_null.php#L16) ( deprecated ) -- [is_numeric](./../../src/Psl/Type/is_numeric.php#L18) ( deprecated ) -- [is_object](./../../src/Psl/Type/is_object.php#L18) ( deprecated ) -- [is_resource](./../../src/Psl/Type/is_resource.php#L20) ( deprecated ) -- [is_scalar](./../../src/Psl/Type/is_scalar.php#L18) ( deprecated ) -- [is_string](./../../src/Psl/Type/is_string.php#L18) ( deprecated ) - [iterable](./../../src/Psl/Type/iterable.php#L20) - [literal_scalar](./../../src/Psl/Type/literal_scalar.php#L14) - [map](./../../src/Psl/Type/map.php#L21) diff --git a/docs/documenter.php b/docs/documenter.php index a5ba4189..49aa7ba8 100644 --- a/docs/documenter.php +++ b/docs/documenter.php @@ -181,7 +181,6 @@ function get_all_components(): array { $components = [ 'Psl', - 'Psl\\Arr', 'Psl\\Class', 'Psl\\Collection', 'Psl\\DataStructure', diff --git a/src/Psl/Arr/at.php b/src/Psl/Arr/at.php deleted file mode 100644 index cde13225..00000000 --- a/src/Psl/Arr/at.php +++ /dev/null @@ -1,34 +0,0 @@ - $array - * @param Tk $key - * - * @throws Psl\Exception\InvariantViolationException If $key is out-of-bounds. - * - * @return Tv - * - * @pure - * - * @deprecated use `$array[$key]` instead. - */ -function at(array $array, $key) -{ - /** @psalm-suppress DeprecatedFunction */ - Psl\invariant(contains_key($array, $key), 'Key (%s) is out-of-bounds.', $key); - - /** @var Tv */ - return $array[$key]; -} diff --git a/src/Psl/Arr/concat.php b/src/Psl/Arr/concat.php deleted file mode 100644 index 40dee06a..00000000 --- a/src/Psl/Arr/concat.php +++ /dev/null @@ -1,25 +0,0 @@ - $first - * @param iterable ...$rest - * - * @return list - * - * @deprecated since 1.2, use Vec\concat instead. - * @see Vec\concat() - */ -function concat(array $first, iterable ...$rest): array -{ - return Vec\concat($first, ...$rest); -} diff --git a/src/Psl/Arr/contains.php b/src/Psl/Arr/contains.php deleted file mode 100644 index 88cb49f2..00000000 --- a/src/Psl/Arr/contains.php +++ /dev/null @@ -1,33 +0,0 @@ - $array - * @param Tv $value - * - * @pure - * - * @deprecated use `Iter\contains` instead. - * @see Iter\contains() - */ -function contains(array $array, $value): bool -{ - foreach ($array as $v) { - if ($value === $v) { - return true; - } - } - - return false; -} diff --git a/src/Psl/Arr/contains_key.php b/src/Psl/Arr/contains_key.php deleted file mode 100644 index e9e85dee..00000000 --- a/src/Psl/Arr/contains_key.php +++ /dev/null @@ -1,28 +0,0 @@ - $array - * @param Tk $key - * - * @pure - * - * @deprecated use `Iter\contains_key()` instead. - * @see Iter\contains_key() - */ -function contains_key(array $array, $key): bool -{ - return array_key_exists($key, $array); -} diff --git a/src/Psl/Arr/count.php b/src/Psl/Arr/count.php deleted file mode 100644 index 01bfbbcb..00000000 --- a/src/Psl/Arr/count.php +++ /dev/null @@ -1,39 +0,0 @@ - Int(3) - * - * Arr\count(Arr\flatten([[1, 2, 3], [4], [5, 6], [7, 8]])) - * => Int(3) - * - * Arr\count(Arr\flatten([[1, 2, 3], [4], [5, 6], [3 => 7, 4 => 8]])) - * => Int(5) - * - * @template Tk of array-key - * @template Tv - * - * @param array $array - * - * @pure - * - * @deprecated use Iter\count instead. - * @see Iter\count() - */ -function count(array $array): int -{ - return \count($array); -} diff --git a/src/Psl/Arr/count_values.php b/src/Psl/Arr/count_values.php deleted file mode 100644 index 457685d0..00000000 --- a/src/Psl/Arr/count_values.php +++ /dev/null @@ -1,25 +0,0 @@ - $values - * - * @return array - * - * @deprecated use `Dict\count_values` instead. - * @see Dict\count_values() - */ -function count_values(iterable $values): array -{ - return Dict\count_values($values); -} diff --git a/src/Psl/Arr/drop.php b/src/Psl/Arr/drop.php deleted file mode 100644 index ce81ee30..00000000 --- a/src/Psl/Arr/drop.php +++ /dev/null @@ -1,34 +0,0 @@ - Arr(4, 5) - * - * @template Tk of array-key - * @template Tv - * - * @param array $array Array to drop the elements from - * @param int $n Number of elements to drop from the start - * - * @throws Psl\Exception\InvariantViolationException If the $n is negative - * - * @return array - * - * @deprecated use `Dict\drop` instead. - * @see Dict\drop() - */ -function drop(iterable $array, int $n): array -{ - return Dict\drop($array, $n); -} diff --git a/src/Psl/Arr/drop_while.php b/src/Psl/Arr/drop_while.php deleted file mode 100644 index e0e3cadc..00000000 --- a/src/Psl/Arr/drop_while.php +++ /dev/null @@ -1,34 +0,0 @@ - $i > 0) - * => Arr(-1, 5) - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $iterable Iterable to drop values from - * @param (callable(Tv): bool) $predicate - * - * @return array - * - * @deprecated use `Dict\drop_while` instead. - * @see Dict\drop_while() - */ -function drop_while(iterable $iterable, callable $predicate): array -{ - return Dict\drop_while($iterable, $predicate); -} diff --git a/src/Psl/Arr/equal.php b/src/Psl/Arr/equal.php deleted file mode 100644 index 65b2bf27..00000000 --- a/src/Psl/Arr/equal.php +++ /dev/null @@ -1,25 +0,0 @@ - $array - * @param array $array2 - * - * @deprecated use `Dict\equal` instead. - * @see Dict\equal() - */ -function equal(array $array, array $array2): bool -{ - return Dict\equal($array, $array2); -} diff --git a/src/Psl/Arr/fill.php b/src/Psl/Arr/fill.php deleted file mode 100644 index 245b4af4..00000000 --- a/src/Psl/Arr/fill.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * @pure - * - * @deprecated use `Vec\fill` instead. - * @see Vec\fill() - */ -function fill(mixed $value, int $start_index, int $num): array -{ - return array_fill($start_index, $num, $value); -} diff --git a/src/Psl/Arr/filter.php b/src/Psl/Arr/filter.php deleted file mode 100644 index 4f4357fa..00000000 --- a/src/Psl/Arr/filter.php +++ /dev/null @@ -1,37 +0,0 @@ - Arr('a', 'b') - * - * Arr\filter(['foo', 'bar', 'baz', 'qux'], fn(string $value): bool => Str\contains($value, 'a')); - * => Arr('bar', 'baz') - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $iterable - * @param (callable(Tv): bool)|null $predicate - * - * @return array - * - * @deprecated use `Dict\filter` instead. - * @see Dict\filter() - */ -function filter(iterable $iterable, ?callable $predicate = null): array -{ - return Dict\filter($iterable, $predicate); -} diff --git a/src/Psl/Arr/filter_keys.php b/src/Psl/Arr/filter_keys.php deleted file mode 100644 index 29c446a0..00000000 --- a/src/Psl/Arr/filter_keys.php +++ /dev/null @@ -1,37 +0,0 @@ - 'a', 1 => 'b']) - * => Arr(1 => 'b') - * - * Arr\filter_keys([0 => 'a', 1 => 'b', 2 => 'c'], fn(int $key): bool => $key <= 1); - * => Arr(0 => 'a', 1 => 'b') - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $iterable - * @param (callable(Tk): bool)|null $predicate - * - * @return array - * - * @deprecated use `Dict\filter_keys` instead. - * @see Dict\filter_keys() - */ -function filter_keys(iterable $iterable, ?callable $predicate = null): array -{ - return Dict\filter_keys($iterable, $predicate); -} diff --git a/src/Psl/Arr/filter_nulls.php b/src/Psl/Arr/filter_nulls.php deleted file mode 100644 index 0f92b2f8..00000000 --- a/src/Psl/Arr/filter_nulls.php +++ /dev/null @@ -1,28 +0,0 @@ - Arr(1, 5) - * - * @template T - * - * @param iterable $iterable - * - * @return list - * - * @deprecated use `Vec\filter_nulls` instead. - * @see Vec\filter_nulls() - */ -function filter_nulls(iterable $iterable): array -{ - return Vec\filter_nulls($iterable); -} diff --git a/src/Psl/Arr/filter_with_key.php b/src/Psl/Arr/filter_with_key.php deleted file mode 100644 index b571d117..00000000 --- a/src/Psl/Arr/filter_with_key.php +++ /dev/null @@ -1,40 +0,0 @@ - Iter('b', 'c') - * - * Arr\filter_with_key( - * ['foo', 'bar', 'baz', 'qux'], - * fn(int $key, string $value): bool => $key > 1 && Str\contains($value, 'a') - * ); - * => Arr('baz') - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $iterable - * @param (callable(Tk, Tv): bool)|null $predicate - * - * @return array - * - * @deprecated use `Dict\filter_with_key` instead. - * @see Dict\filter_with_key() - */ -function filter_with_key(iterable $iterable, ?callable $predicate = null): array -{ - return Dict\filter_with_key($iterable, $predicate); -} diff --git a/src/Psl/Arr/first.php b/src/Psl/Arr/first.php deleted file mode 100644 index 17554062..00000000 --- a/src/Psl/Arr/first.php +++ /dev/null @@ -1,36 +0,0 @@ - $array - * - * @return Tv|null - * - * @pure - * - * @deprecated use `Iter\first()` instead. - * @see Iter\first() - */ -function first(array $array) -{ - /** - * @psalm-suppress DeprecatedFunction - */ - $first = first_key($array); - - if (null === $first) { - return null; - } - - return $array[$first]; -} diff --git a/src/Psl/Arr/first_key.php b/src/Psl/Arr/first_key.php deleted file mode 100644 index b2183f14..00000000 --- a/src/Psl/Arr/first_key.php +++ /dev/null @@ -1,28 +0,0 @@ - $array - * - * @return Tk|null - * - * @pure - * - * @deprecated use `Iter\first_key` instead. - * @see Iter\first_key() - */ -function first_key(array $array) -{ - return array_key_first($array); -} diff --git a/src/Psl/Arr/firstx.php b/src/Psl/Arr/firstx.php deleted file mode 100644 index 4b6be68d..00000000 --- a/src/Psl/Arr/firstx.php +++ /dev/null @@ -1,37 +0,0 @@ - $array - * - * @throws Psl\Exception\InvariantViolationException If $array is empty. - * - * @return Tv - * - * @pure - * - * @deprecated use `Iter\first` instead. - * @see Iter\first() - */ -function firstx(array $array) -{ - /** - * @psalm-suppress DeprecatedFunction - */ - $first = first_key($array); - Psl\invariant(null !== $first, 'Expected a non-empty array.'); - - return $array[$first]; -} diff --git a/src/Psl/Arr/flat_map.php b/src/Psl/Arr/flat_map.php deleted file mode 100644 index 66788b0a..00000000 --- a/src/Psl/Arr/flat_map.php +++ /dev/null @@ -1,25 +0,0 @@ - $iterable Iterable to be mapped over - * @param (callable(Tv): iterable) $mapper - * - * @return list - * - * @deprecated use `Vec\flat_map` instead. - * @see Vec\flat_map() - */ -function flat_map(iterable $iterable, callable $mapper): array -{ - return Vec\flat_map($iterable, $mapper); -} diff --git a/src/Psl/Arr/flatten.php b/src/Psl/Arr/flatten.php deleted file mode 100644 index 78a0dac3..00000000 --- a/src/Psl/Arr/flatten.php +++ /dev/null @@ -1,36 +0,0 @@ - Arr(0 => 9, 1 => 8) - * - * Arr\flatten([[0 => 1, 1 => 2], [2 => 9, 3 => 8]]) - * => Arr(0 => 1, 1 => 2, 2 => 9, 3 => 8) - * - * @template Tk of array-key - * @template Tv - * - * @param iterable> $iterables - * - * @return array - * - * @deprecated use `Dict\flatten` instead. - * @see Dict\flatten() - */ -function flatten(iterable $iterables): array -{ - return Dict\flatten($iterables); -} diff --git a/src/Psl/Arr/flip.php b/src/Psl/Arr/flip.php deleted file mode 100644 index 535d0697..00000000 --- a/src/Psl/Arr/flip.php +++ /dev/null @@ -1,31 +0,0 @@ - 1, 'b' => 2, 'c' => 3]) - * => Arr(1 => 'a', 2 => 'b', 3 => 'c') - * - * @template Tk of array-key - * @template Tv of array-key - * - * @param array $array - * - * @return array - * - * @deprecated use `Dict\flip` instead. - * @see Dict\flip() - */ -function flip(array $array): array -{ - return Dict\flip($array); -} diff --git a/src/Psl/Arr/group_by.php b/src/Psl/Arr/group_by.php deleted file mode 100644 index 91254615..00000000 --- a/src/Psl/Arr/group_by.php +++ /dev/null @@ -1,46 +0,0 @@ - $i < 2 ? null : $i + 5 - * ) - * => Arr( - * 7 => [2], 8 => [3], 9 => [4], 10 => [5], 11 => [6], 12 => [7], 13 => [8], 14 => [9], 15 => [10] - * ) - * - * Arr\group_by( - * [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - * fn($i) => $i < 2 ? null : ($i >= 7 ? 12 : $i +5) - * ) - * => Arr(7 => [2], 8 => [3], 9 => [4], 10 => [5], 11 => [6], 12 => [7, 8, 9, 10]) - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $values - * @param (callable(Tv): ?Tk) $key_func - * - * @return array> - * - * @deprecated use `Dict\group_by` instead. - * @see Dict\group_by() - */ -function group_by(iterable $values, callable $key_func): array -{ - return Dict\group_by($values, $key_func); -} diff --git a/src/Psl/Arr/idx.php b/src/Psl/Arr/idx.php deleted file mode 100644 index 633c283e..00000000 --- a/src/Psl/Arr/idx.php +++ /dev/null @@ -1,43 +0,0 @@ - $array - * @param Tk $index - * @param Tv $default - * - * @return Tv - * - * @pure - * - * @deprecated use `$array[$index] ?? $default` instead. - */ -function idx(array $array, $index, $default = null) -{ - /** @psalm-suppress DeprecatedFunction */ - if (contains_key($array, $index)) { - return $array[$index]; - } - - return $default; -} diff --git a/src/Psl/Arr/keys.php b/src/Psl/Arr/keys.php deleted file mode 100644 index c3884035..00000000 --- a/src/Psl/Arr/keys.php +++ /dev/null @@ -1,25 +0,0 @@ - $arr - * - * @return list - * - * @deprecated use `Vec\keys` instead. - * @see Vec\keys() - */ -function keys(array $arr): array -{ - return Vec\keys($arr); -} diff --git a/src/Psl/Arr/last.php b/src/Psl/Arr/last.php deleted file mode 100644 index a1e1a6da..00000000 --- a/src/Psl/Arr/last.php +++ /dev/null @@ -1,35 +0,0 @@ - $array - * - * @return Tv|null - * - * @pure - * - * @deprecated use `Iter\last` instead. - * @see Iter\last() - */ -function last(array $array) -{ - /** - * @psalm-suppress DeprecatedFunction - */ - $last = last_key($array); - if (null === $last) { - return null; - } - - return $array[$last]; -} diff --git a/src/Psl/Arr/last_key.php b/src/Psl/Arr/last_key.php deleted file mode 100644 index 9be406e4..00000000 --- a/src/Psl/Arr/last_key.php +++ /dev/null @@ -1,30 +0,0 @@ - $array - * - * @return Tk|null - * - * @pure - * - * @deprecated use `Iter\last_key` instead. - * @see Iter\last_key() - */ -function last_key(array $array) -{ - /** @var Tk|null */ - return array_key_last($array); -} diff --git a/src/Psl/Arr/lastx.php b/src/Psl/Arr/lastx.php deleted file mode 100644 index eae10d72..00000000 --- a/src/Psl/Arr/lastx.php +++ /dev/null @@ -1,37 +0,0 @@ - $array - * - * @throws Psl\Exception\InvariantViolationException If $array is empty. - * - * @return Tv - * - * @pure - * - * @deprecated use `Iter\last` instead. - * @see Iter\last() - */ -function lastx(array $array) -{ - /** - * @psalm-suppress DeprecatedFunction - */ - $last = last_key($array); - Psl\invariant(null !== $last, 'Expected a non-empty array.'); - - return $array[$last]; -} diff --git a/src/Psl/Arr/map.php b/src/Psl/Arr/map.php deleted file mode 100644 index a929ea32..00000000 --- a/src/Psl/Arr/map.php +++ /dev/null @@ -1,37 +0,0 @@ - $i * 2); - * => Arr(2, 4, 6, 8, 10) - * - * @template Tk of array-key - * @template Tv - * @template T - * - * @param iterable $iterable Iterable to be mapped over - * @param (callable(Tv): T) $function - * - * @return array - * - * @deprecated use `Dict\map` instead. - * @see Dict\map() - */ -function map(iterable $iterable, callable $function): array -{ - return Dict\map($iterable, $function); -} diff --git a/src/Psl/Arr/map_keys.php b/src/Psl/Arr/map_keys.php deleted file mode 100644 index b8e6f43f..00000000 --- a/src/Psl/Arr/map_keys.php +++ /dev/null @@ -1,37 +0,0 @@ - 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5], fn($i) => $i * 2); - * => Arr(0 => 1, 2 => 2, 4 => 3, 6 => 4, 8 => 5) - * - * @template Tk1 of array-key - * @template Tk2 of array-key - * @template Tv - * - * @param iterable $iterable Iterable to be mapped over - * @param (callable(Tk1): Tk2) $function - * - * @return array - * - * @deprecated use `Dict\map_keys` instead. - * @see Dict\map() - */ -function map_keys(iterable $iterable, callable $function): array -{ - return Dict\map_keys($iterable, $function); -} diff --git a/src/Psl/Arr/map_with_key.php b/src/Psl/Arr/map_with_key.php deleted file mode 100644 index 7fe139d5..00000000 --- a/src/Psl/Arr/map_with_key.php +++ /dev/null @@ -1,37 +0,0 @@ - $k + $v); - * => Arr(1, 3, 5, 7, 9) - * - * @template Tk of array-key - * @template Tv - * @template T - * - * @param iterable $iterable Iterable to be mapped over - * @param (callable(Tk,Tv): T) $function - * - * @return array - * - * @deprecated use `Dict\map_with_key` instead. - * @see Dict\map_with_key() - */ -function map_with_key(iterable $iterable, callable $function): array -{ - return Dict\map_with_key($iterable, $function); -} diff --git a/src/Psl/Arr/merge.php b/src/Psl/Arr/merge.php deleted file mode 100644 index f6bab6f4..00000000 --- a/src/Psl/Arr/merge.php +++ /dev/null @@ -1,40 +0,0 @@ - Arr(0 => 9, 1 => 8) - * - * Arr\merge([0 => 1, 1 => 2], [2 => 9, 3 => 8]) - * => Arr(0 => 1, 1 => 2, 2 => 9, 3 => 8) - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $first - * @param iterable ...$rest - * - * @return array - * - * @deprecated use `Dict\merge` instead. - * @see Dict\merge() - * - * @no-named-arguments - */ -function merge(iterable $first, iterable ...$rest): array -{ - /** @var list> $iterables */ - $iterables = [$first, ...$rest]; - - return Dict\flatten($iterables); -} diff --git a/src/Psl/Arr/partition.php b/src/Psl/Arr/partition.php deleted file mode 100644 index a2c1988a..00000000 --- a/src/Psl/Arr/partition.php +++ /dev/null @@ -1,25 +0,0 @@ - $list - * @param (callable(T): bool) $predicate - * - * @return array{0: list, 1: list} - * - * @deprecated use `Vec\partition` instead. - * @see Vec\partition - */ -function partition(iterable $list, callable $predicate): array -{ - return Vec\partition($list, $predicate); -} diff --git a/src/Psl/Arr/random.php b/src/Psl/Arr/random.php deleted file mode 100644 index 267588d0..00000000 --- a/src/Psl/Arr/random.php +++ /dev/null @@ -1,28 +0,0 @@ - $values - * - * @throws Psl\Exception\InvariantViolationException If $values is empty. - * - * @return Tv - * - * @deprecated use `Iter\random` instead. - * @see Iter\random() - */ -function random(array $values) -{ - return Iter\random($values); -} diff --git a/src/Psl/Arr/select_keys.php b/src/Psl/Arr/select_keys.php deleted file mode 100644 index 53e59cc4..00000000 --- a/src/Psl/Arr/select_keys.php +++ /dev/null @@ -1,28 +0,0 @@ - $array - * @param list $keys - * - * @return array - * - * @deprecated use `Dict\select_keys` instead. - * @see Dict\select_keys() - */ -function select_keys(array $array, array $keys): array -{ - return Dict\select_keys($array, $keys); -} diff --git a/src/Psl/Arr/shuffle.php b/src/Psl/Arr/shuffle.php deleted file mode 100644 index 84636747..00000000 --- a/src/Psl/Arr/shuffle.php +++ /dev/null @@ -1,33 +0,0 @@ - Arr(2, 3, 1) - * - * Arr\shuffle(['a' => 1, 'b' => 2, 'c' => 3]) - * => Arr(2, 3, 1) - * - * @template Tk of array-key - * @template Tv - * - * @param array $array - * - * @return list the shuffled array. - * - * @deprecated since 1.2, use Vec\shuffle instead. - * @see Vec\shuffle() - */ -function shuffle(array $array): array -{ - return Vec\shuffle($array); -} diff --git a/src/Psl/Arr/slice.php b/src/Psl/Arr/slice.php deleted file mode 100644 index 07c20d77..00000000 --- a/src/Psl/Arr/slice.php +++ /dev/null @@ -1,38 +0,0 @@ - Arr(0, 1, 2, 3, 4, 5) - * - * Arr\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5, 3) - * => Arr(0, 1, 2) - * - * @template Tk of array-key - * @template Tv - * - * @param array $array Array to take the slice from - * @param int $start Start offset - * @param int $length Length (if not specified all remaining values from the array are used) - * - * @throws Psl\Exception\InvariantViolationException If the $start offset or $length are negative - * - * @return array - * - * @deprecated use `Dict\slice()` instead. - * @see Dict\slice() - */ -function slice(array $array, int $start, ?int $length = null): array -{ - return Dict\slice($array, $start, $length); -} diff --git a/src/Psl/Arr/sort.php b/src/Psl/Arr/sort.php deleted file mode 100644 index c322c475..00000000 --- a/src/Psl/Arr/sort.php +++ /dev/null @@ -1,27 +0,0 @@ - $array - * @param (callable(T, T): int)|null $comparator - * - * @return list - * - * @deprecated since 1.2, use Vec\sort instead. - */ -function sort(iterable $array, ?callable $comparator = null): array -{ - return Vec\sort($array, $comparator); -} diff --git a/src/Psl/Arr/sort_by.php b/src/Psl/Arr/sort_by.php deleted file mode 100644 index 207ae232..00000000 --- a/src/Psl/Arr/sort_by.php +++ /dev/null @@ -1,30 +0,0 @@ - $iterable - * @param (callable(Tv): Ts) $scalar_func - * @param (callable(Ts, Ts): int)|null $comparator - * - * @return list - * - * @deprecated since 1.2, use Vec\sort_by instead. - */ -function sort_by(iterable $iterable, callable $scalar_func, ?callable $comparator = null): array -{ - return Vec\sort_by($iterable, $scalar_func, $comparator); -} diff --git a/src/Psl/Arr/sort_by_key.php b/src/Psl/Arr/sort_by_key.php deleted file mode 100644 index ebdbee83..00000000 --- a/src/Psl/Arr/sort_by_key.php +++ /dev/null @@ -1,28 +0,0 @@ - $array - * @param (callable(Tk, Tk): int)|null $comparator - * - * @return array - * - * @deprecated use `Dict\sort_by_key` - * @see Dict\sort_by_key - */ -function sort_by_key(array $array, ?callable $comparator = null): array -{ - return Dict\sort_by_key($array, $comparator); -} diff --git a/src/Psl/Arr/sort_with_keys.php b/src/Psl/Arr/sort_with_keys.php deleted file mode 100644 index 41a02eaa..00000000 --- a/src/Psl/Arr/sort_with_keys.php +++ /dev/null @@ -1,28 +0,0 @@ - $array - * @param (callable(Tv, Tv): int)|null $comparator - * - * @return array - * - * @deprecated use `Dict\sort` instead - * @see Dict\sort() - */ -function sort_with_keys(array $array, ?callable $comparator = null): array -{ - return Dict\sort($array, $comparator); -} diff --git a/src/Psl/Arr/sort_with_keys_by.php b/src/Psl/Arr/sort_with_keys_by.php deleted file mode 100644 index 470187dd..00000000 --- a/src/Psl/Arr/sort_with_keys_by.php +++ /dev/null @@ -1,32 +0,0 @@ - $iterable - * @param (callable(Tv): Ts) $scalar_func - * @param (callable(Ts, Ts): int)|null $comparator - * - * @return array - * - * @deprecated use `Dict\sort_by` instead - * @see Dict\sort_by() - */ -function sort_with_keys_by(iterable $iterable, callable $scalar_func, ?callable $comparator = null): array -{ - return Dict\sort_by($iterable, $scalar_func, $comparator); -} diff --git a/src/Psl/Arr/take.php b/src/Psl/Arr/take.php deleted file mode 100644 index 4a04630c..00000000 --- a/src/Psl/Arr/take.php +++ /dev/null @@ -1,28 +0,0 @@ - $array - * - * @throws Psl\Exception\InvariantViolationException If the $n is negative - * - * @return array - * - * @deprecated use `Dict\take` instead. - * @see Dict\take() - */ -function take(iterable $array, int $n): array -{ - return Dict\take($array, $n); -} diff --git a/src/Psl/Arr/take_while.php b/src/Psl/Arr/take_while.php deleted file mode 100644 index 2c228b05..00000000 --- a/src/Psl/Arr/take_while.php +++ /dev/null @@ -1,34 +0,0 @@ - $i > 0) - * => Iter(3, 1, 4) - * - * @template Tk of array-key - * @template Tv - * - * @param iterable $iterable Iterable to take values from - * @param (callable(Tv): bool) $predicate - * - * @return array - * - * @deprecated use `Dict\take_while` instead. - * @see Dict\take_while() - */ -function take_while(iterable $iterable, callable $predicate): array -{ - return Dict\take_while($iterable, $predicate); -} diff --git a/src/Psl/Arr/unique.php b/src/Psl/Arr/unique.php deleted file mode 100644 index 8fd534b1..00000000 --- a/src/Psl/Arr/unique.php +++ /dev/null @@ -1,25 +0,0 @@ - $iterable - * - * @return array - * - * @deprecated use `Dict\unique` instead - * @see Dict\unique - */ -function unique(iterable $iterable): array -{ - return Dict\unique($iterable); -} diff --git a/src/Psl/Arr/unique_by.php b/src/Psl/Arr/unique_by.php deleted file mode 100644 index 9cd254ea..00000000 --- a/src/Psl/Arr/unique_by.php +++ /dev/null @@ -1,29 +0,0 @@ - $iterable - * @param (callable(Tv): Ts) $scalar_func - * - * @return array - * - * @deprecated use `Dict\unique_by` instead - * @see Dict\unique_by - */ -function unique_by(iterable $iterable, callable $scalar_func): array -{ - return Dict\unique_by($iterable, $scalar_func); -} diff --git a/src/Psl/Arr/values.php b/src/Psl/Arr/values.php deleted file mode 100644 index 517aa938..00000000 --- a/src/Psl/Arr/values.php +++ /dev/null @@ -1,28 +0,0 @@ - $arr - * - * @return list - * - * @pure - * - * @deprecated since 1.2, use Vec\values instead. - * @see Vec\values() - */ -function values(array $arr): array -{ - return array_values($arr); -} diff --git a/src/Psl/Dict/sort.php b/src/Psl/Dict/sort.php index cfa158e3..44aea78b 100644 --- a/src/Psl/Dict/sort.php +++ b/src/Psl/Dict/sort.php @@ -29,7 +29,14 @@ function sort(iterable $iterable, ?callable $comparator = null): array } if (null !== $comparator) { - uasort($array, $comparator); + uasort( + $array, + /** + * @param Tv $a + * @param Tv $b + */ + static fn(mixed $a, mixed $b): int => $comparator($a, $b) + ); } else { asort($array); } diff --git a/src/Psl/Internal/Loader.php b/src/Psl/Internal/Loader.php index bfee6877..29fb7a26 100644 --- a/src/Psl/Internal/Loader.php +++ b/src/Psl/Internal/Loader.php @@ -58,51 +58,6 @@ final class Loader ]; public const FUNCTIONS = [ - 'Psl\Arr\at', - 'Psl\Arr\concat', - 'Psl\Arr\contains', - 'Psl\Arr\contains_key', - 'Psl\Arr\count', - 'Psl\Arr\count_values', - 'Psl\Arr\equal', - 'Psl\Arr\fill', - 'Psl\Arr\first', - 'Psl\Arr\first_key', - 'Psl\Arr\firstx', - 'Psl\Arr\flatten', - 'Psl\Arr\flat_map', - 'Psl\Arr\flip', - 'Psl\Arr\group_by', - 'Psl\Arr\idx', - 'Psl\Arr\keys', - 'Psl\Arr\last', - 'Psl\Arr\last_key', - 'Psl\Arr\lastx', - 'Psl\Arr\merge', - 'Psl\Arr\partition', - 'Psl\Arr\random', - 'Psl\Arr\select_keys', - 'Psl\Arr\shuffle', - 'Psl\Arr\sort', - 'Psl\Arr\sort_by', - 'Psl\Arr\sort_by_key', - 'Psl\Arr\sort_with_keys', - 'Psl\Arr\sort_with_keys_by', - 'Psl\Arr\unique', - 'Psl\Arr\unique_by', - 'Psl\Arr\values', - 'Psl\Arr\drop', - 'Psl\Arr\drop_while', - 'Psl\Arr\slice', - 'Psl\Arr\take', - 'Psl\Arr\take_while', - 'Psl\Arr\filter', - 'Psl\Arr\filter_keys', - 'Psl\Arr\filter_nulls', - 'Psl\Arr\filter_with_key', - 'Psl\Arr\map', - 'Psl\Arr\map_keys', - 'Psl\Arr\map_with_key', 'Psl\Dict\associate', 'Psl\Dict\count_values', 'Psl\Dict\drop', @@ -159,58 +114,21 @@ final class Loader 'Psl\Iter\all', 'Psl\Iter\any', 'Psl\Iter\apply', - 'Psl\Iter\chain', - 'Psl\Iter\chunk', - 'Psl\Iter\chunk_with_keys', 'Psl\Iter\contains', 'Psl\Iter\contains_key', 'Psl\Iter\count', - 'Psl\Iter\diff_by_key', - 'Psl\Iter\drop', - 'Psl\Iter\drop_while', - 'Psl\Iter\enumerate', - 'Psl\Iter\filter', - 'Psl\Iter\filter_keys', - 'Psl\Iter\filter_nulls', - 'Psl\Iter\filter_with_key', 'Psl\Iter\first', 'Psl\Iter\first_key', - 'Psl\Iter\flat_map', - 'Psl\Iter\flatten', - 'Psl\Iter\flip', - 'Psl\Iter\from_entries', - 'Psl\Iter\from_keys', 'Psl\Iter\is_empty', - 'Psl\Iter\keys', 'Psl\Iter\last', 'Psl\Iter\last_key', - 'Psl\Iter\map', - 'Psl\Iter\map_keys', - 'Psl\Iter\map_with_key', - 'Psl\Iter\merge', - 'Psl\Iter\product', - 'Psl\Iter\pull', - 'Psl\Iter\pull_with_key', 'Psl\Iter\random', - 'Psl\Iter\range', 'Psl\Iter\reduce', 'Psl\Iter\reduce_keys', 'Psl\Iter\reduce_with_keys', - 'Psl\Iter\reductions', - 'Psl\Iter\reindex', - 'Psl\Iter\repeat', - 'Psl\Iter\reproduce', - 'Psl\Iter\reverse', 'Psl\Iter\rewindable', 'Psl\Iter\search', - 'Psl\Iter\slice', - 'Psl\Iter\take', - 'Psl\Iter\take_while', - 'Psl\Iter\to_array', - 'Psl\Iter\to_array_with_keys', 'Psl\Iter\to_iterator', - 'Psl\Iter\values', - 'Psl\Iter\zip', 'Psl\Vec\chunk', 'Psl\Vec\chunk_with_keys', 'Psl\Vec\concat', @@ -411,21 +329,7 @@ final class Loader 'Psl\Type\union', 'Psl\Type\vec', 'Psl\Type\dict', - 'Psl\Type\is_array', - 'Psl\Type\is_arraykey', - 'Psl\Type\is_bool', - 'Psl\Type\is_callable', - 'Psl\Type\is_float', - 'Psl\Type\is_instanceof', - 'Psl\Type\is_int', - 'Psl\Type\is_iterable', 'Psl\Type\is_nan', - 'Psl\Type\is_null', - 'Psl\Type\is_numeric', - 'Psl\Type\is_object', - 'Psl\Type\is_resource', - 'Psl\Type\is_scalar', - 'Psl\Type\is_string', 'Psl\Type\literal_scalar', 'Psl\Json\encode', 'Psl\Json\decode', diff --git a/src/Psl/Iter/chain.php b/src/Psl/Iter/chain.php deleted file mode 100644 index 926d6141..00000000 --- a/src/Psl/Iter/chain.php +++ /dev/null @@ -1,38 +0,0 @@ - Iter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) - * - * @template Tk - * @template Tv - * - * @param iterable ...$iterables Iterables to chain - * - * @return Iterator - * - * @deprecated use `Vec\concat` instead. - * @see Vec\concat() - */ -function chain(iterable ...$iterables): Iterator -{ - return Iterator::from(static function () use ($iterables): Generator { - foreach ($iterables as $iterable) { - yield from $iterable; - } - }); -} diff --git a/src/Psl/Iter/chunk.php b/src/Psl/Iter/chunk.php deleted file mode 100644 index 22173d06..00000000 --- a/src/Psl/Iter/chunk.php +++ /dev/null @@ -1,42 +0,0 @@ - Iter([1, 2], [3, 4], [5]) - * - * @template T - * - * @param iterable $iterable The iterable to chunk - * @param int $size The size of each chunk - * - * @throws Psl\Exception\InvariantViolationException If $size is negative. - * - * @return Iterator> - * - * @deprecated since 1.2, use Vec\chunk instead. - */ -function chunk(iterable $iterable, int $size): Iterator -{ - Psl\invariant($size > 0, 'Expected a non-negative size.'); - - return Iterator::from(static function () use ($iterable, $size): Generator { - foreach (Vec\chunk($iterable, $size) as $chunk) { - yield $chunk; - } - }); -} diff --git a/src/Psl/Iter/chunk_with_keys.php b/src/Psl/Iter/chunk_with_keys.php deleted file mode 100644 index 93eb9690..00000000 --- a/src/Psl/Iter/chunk_with_keys.php +++ /dev/null @@ -1,51 +0,0 @@ - 1, 'b' => 2, 'c' => 3], 2) - * => Iter(['a' => 1, 'b' => 2], ['c' => 3]) - * - * @template Tk - * @template Tv - * - * @param iterable $iterable The iterable to chunk - * @param int $size The size of each chunk - * - * @throws Psl\Exception\InvariantViolationException If $size is negative. - * - * @return Iterator> - * - * @deprecated since 1.2, use Vec\chunk_with_keys instead. - */ -function chunk_with_keys(iterable $iterable, int $size): Iterator -{ - Psl\invariant($size > 0, 'Expected a non-negative size.'); - - return Iterator::from(static function () use ($iterable, $size): Generator { - $chunk = []; - $count = 0; - foreach ($iterable as $key => $value) { - $chunk[$key] = $value; - ++$count; - if ($count === $size) { - yield $chunk; - $count = 0; - $chunk = []; - } - } - - if (0 !== $count) { - yield $chunk; - } - }); -} diff --git a/src/Psl/Iter/diff_by_key.php b/src/Psl/Iter/diff_by_key.php deleted file mode 100644 index 4bbefd5d..00000000 --- a/src/Psl/Iter/diff_by_key.php +++ /dev/null @@ -1,52 +0,0 @@ - $first - * @param iterable $second - * @param iterable ...$rest - * - * @return Iterator - * - * @deprecated use `Dict\diff_by_key` instead. - * @see Dict\diff_by_key() - */ -function diff_by_key(iterable $first, iterable $second, iterable ...$rest): Iterator -{ - return Iterator::from(static function () use ($first, $second, $rest): Generator { - if (is_empty($first)) { - return; - } - - if (is_empty($second) && all($rest, static fn (iterable $iter): bool => is_empty($iter))) { - yield from $first; - } - - // We don't use arrays here to ensure we allow the usage of non-arraykey indexes. - /** @var Generator $second */ - $second = ((static fn (iterable $iterable): Generator => yield from $iterable)($second)); - /** @var Generator, mixed, mixed, void> $generator */ - $generator = ((static function (Generator $second, iterable ...$rest): Generator { - yield from $second; - foreach ($rest as $iterable) { - yield from $iterable; - } - })($second, ...$rest)); - $rewindable = rewindable($generator); - - foreach ($first as $k => $v) { - if (!contains_key($rewindable, $k)) { - yield $k => $v; - } - } - }); -} diff --git a/src/Psl/Iter/drop.php b/src/Psl/Iter/drop.php deleted file mode 100644 index 18d1b076..00000000 --- a/src/Psl/Iter/drop.php +++ /dev/null @@ -1,35 +0,0 @@ - Iter(4, 5) - * - * @template Tk - * @template Tv - * - * @param iterable $iterable Iterable to drop the elements from - * @param int $n Number of elements to drop from the start - * - * @throws Psl\Exception\InvariantViolationException If the $n is negative - * - * @return Iterator - * - * @deprecated use `Dict\drop` instead. - * @see Dict\drop() - */ -function drop(iterable $iterable, int $n): Iterator -{ - /** @psalm-suppress DeprecatedFunction */ - return slice($iterable, $n); -} diff --git a/src/Psl/Iter/drop_while.php b/src/Psl/Iter/drop_while.php deleted file mode 100644 index 8860fcd5..00000000 --- a/src/Psl/Iter/drop_while.php +++ /dev/null @@ -1,45 +0,0 @@ - $i > 0) - * => Iter(-1, 5) - * - * @template Tk - * @template Tv - * - * @param iterable $iterable Iterable to drop values from - * @param (callable(Tv): bool) $predicate - * - * @return Iterator - * - * @deprecated use `Dict\drop_while` instead. - */ -function drop_while(iterable $iterable, callable $predicate): Iterator -{ - return Iterator::from(static function () use ($iterable, $predicate): Generator { - $failed = false; - foreach ($iterable as $key => $value) { - if (!$failed && !$predicate($value)) { - $failed = true; - } - - if ($failed) { - yield $key => $value; - } - } - }); -} diff --git a/src/Psl/Iter/enumerate.php b/src/Psl/Iter/enumerate.php deleted file mode 100644 index beac7927..00000000 --- a/src/Psl/Iter/enumerate.php +++ /dev/null @@ -1,30 +0,0 @@ - $iterable - * - * @return Iterator - * - * @deprecated use `Vec\enumerate` instead. - * @see Vec\enumerate() - */ -function enumerate(iterable $iterable): Iterator -{ - return Iterator::from(static function () use ($iterable): Generator { - foreach ($iterable as $k => $v) { - yield [$k, $v]; - } - }); -} diff --git a/src/Psl/Iter/filter.php b/src/Psl/Iter/filter.php deleted file mode 100644 index 0422a98b..00000000 --- a/src/Psl/Iter/filter.php +++ /dev/null @@ -1,45 +0,0 @@ - Iter('a', 'b') - * - * Iter\filter(['foo', 'bar', 'baz', 'qux'], fn($value) => Str\contains($value, 'a')); - * => Iter('bar', 'baz') - * - * @template Tk - * @template Tv - * - * @param iterable $iterable - * @param (callable(Tv): bool)|null $predicate - * - * @return Iterator - * - * @deprecated use `Dict\filter` instead. - * @see Dict\filter() - */ -function filter(iterable $iterable, ?callable $predicate = null): Iterator -{ - return Iterator::from(static function () use ($iterable, $predicate): Generator { - /** @var (callable(Tv): bool) $predicate */ - $predicate = $predicate ?? Closure::fromCallable('Psl\Internal\boolean'); - foreach ($iterable as $k => $v) { - if ($predicate($v)) { - yield $k => $v; - } - } - }); -} diff --git a/src/Psl/Iter/filter_keys.php b/src/Psl/Iter/filter_keys.php deleted file mode 100644 index ef323760..00000000 --- a/src/Psl/Iter/filter_keys.php +++ /dev/null @@ -1,47 +0,0 @@ - 'a', 1 => 'b']) - * => Iter(1 => 'b') - * - * Iter\filter_keys([0 => 'a', 1 => 'b', 2 => 'c'], fn($key) => $key <= 1); - * => Iter(0 => 'a', 1 => 'b') - * - * @template Tk - * @template Tv - * - * @param iterable $iterable - * @param (callable(Tk): bool)|null $predicate - * - * @return Iterator - * - * @deprecated use `Dict\filter_keys` instead. - * @see Dict\filter_keys() - */ -function filter_keys(iterable $iterable, ?callable $predicate = null): Iterator -{ - return Iterator::from(static function () use ($iterable, $predicate): Generator { - /** @var (callable(Tk): bool) $predicate */ - $predicate = $predicate ?? Closure::fromCallable('Psl\Internal\boolean'); - foreach ($iterable as $k => $v) { - if ($predicate($k)) { - yield $k => $v; - } - } - }); -} diff --git a/src/Psl/Iter/filter_nulls.php b/src/Psl/Iter/filter_nulls.php deleted file mode 100644 index 525eb1f9..00000000 --- a/src/Psl/Iter/filter_nulls.php +++ /dev/null @@ -1,35 +0,0 @@ - Iter(1, 5) - * - * @template T - * - * @param iterable $iterable - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\filter_nulls instead. - * @see Vec\filter_nulls() - */ -function filter_nulls(iterable $iterable): Iterator -{ - return Iterator::from(static function () use ($iterable): Generator { - foreach ($iterable as $value) { - if (null !== $value) { - yield $value; - } - } - }); -} diff --git a/src/Psl/Iter/filter_with_key.php b/src/Psl/Iter/filter_with_key.php deleted file mode 100644 index d7da7cdb..00000000 --- a/src/Psl/Iter/filter_with_key.php +++ /dev/null @@ -1,57 +0,0 @@ - Iter('b', 'c') - * - * Iter\filter_with_key( - * ['foo', 'bar', 'baz', 'qux'], - * fn($key, $value) => $key > 1 && Str\contains($value, 'a') - * ); - * => Iter('baz') - * - * @template Tk - * @template Tv - * - * @param iterable $iterable - * @param (callable(Tk, Tv): bool)|null $predicate - * - * @return Iterator - * - * @deprecated use `Dict\filter_with_key` instead. - * @see Dict\filter_with_key() - */ -function filter_with_key(iterable $iterable, ?callable $predicate = null): Iterator -{ - return Iterator::from(static function () use ($iterable, $predicate): Generator { - $predicate = $predicate ?? - /** - * @param Tk $_k - * @param Tv $v - * - * @return bool - */ - static fn ($_k, $v) => Psl\Internal\boolean($v); - - foreach ($iterable as $k => $v) { - if ($predicate($k, $v)) { - yield $k => $v; - } - } - }); -} diff --git a/src/Psl/Iter/flat_map.php b/src/Psl/Iter/flat_map.php deleted file mode 100644 index c161a665..00000000 --- a/src/Psl/Iter/flat_map.php +++ /dev/null @@ -1,31 +0,0 @@ - $iterable Iterable to be mapped over - * @param (callable(Tv): iterable) $mapper - * - * @return iterable - * - * @deprecated since 1.2, use Vec\flat_map instead. - * @see Vec\flat_map() - */ -function flat_map(iterable $iterable, callable $mapper): iterable -{ - return Iterator::from(static function () use ($iterable, $mapper) { - foreach ($iterable as $value) { - foreach ($mapper($value) as $item) { - yield $item; - } - } - }); -} diff --git a/src/Psl/Iter/flatten.php b/src/Psl/Iter/flatten.php deleted file mode 100644 index dfc75c54..00000000 --- a/src/Psl/Iter/flatten.php +++ /dev/null @@ -1,33 +0,0 @@ -> $iterables - * - * @return Iterator - * - * @deprecated use `Dict\flatten` instead. - * @see Dict\flatten() - */ -function flatten(iterable $iterables): Iterator -{ - return Iterator::from(static function () use ($iterables): Generator { - foreach ($iterables as $iterable) { - foreach ($iterable as $key => $value) { - yield $key => $value; - } - } - }); -} diff --git a/src/Psl/Iter/flip.php b/src/Psl/Iter/flip.php deleted file mode 100644 index 4b07f2df..00000000 --- a/src/Psl/Iter/flip.php +++ /dev/null @@ -1,34 +0,0 @@ - 1, 'b' => 2, 'c' => 3]) - * => Iter(1 => 'a', 2 => 'b', 3 => 'c') - * - * @template Tk - * @template Tv - * - * @param iterable $iterable - * - * @return Iterator - * - * @deprecated use `Dict\flip` instead. - * @see Dict\flip() - */ -function flip(iterable $iterable): Iterator -{ - return Iterator::from(static function () use ($iterable): Generator { - foreach ($iterable as $k => $v) { - yield $v => $k; - } - }); -} diff --git a/src/Psl/Iter/from_entries.php b/src/Psl/Iter/from_entries.php deleted file mode 100644 index f6c3aa0d..00000000 --- a/src/Psl/Iter/from_entries.php +++ /dev/null @@ -1,31 +0,0 @@ - $entries - * - * @return Iterator - * - * @deprecated use `Dict\from_entries` instead. - * @see Dict\from_entries() - */ -function from_entries(iterable $entries): Iterator -{ - return Iterator::from(static function () use ($entries): Generator { - foreach ($entries as [$key, $value]) { - yield $key => $value; - } - }); -} diff --git a/src/Psl/Iter/from_keys.php b/src/Psl/Iter/from_keys.php deleted file mode 100644 index 6415ffec..00000000 --- a/src/Psl/Iter/from_keys.php +++ /dev/null @@ -1,32 +0,0 @@ - $keys - * @param (callable(Tk): Tv) $value_func - * - * @return Iterator - * - * @deprecated use `Dict\from_keys` instead. - * @see Dict\from_keys() - */ -function from_keys(iterable $keys, callable $value_func): Iterator -{ - return Iterator::from(static function () use ($keys, $value_func): Generator { - foreach ($keys as $key) { - yield $key => $value_func($key); - } - }); -} diff --git a/src/Psl/Iter/keys.php b/src/Psl/Iter/keys.php deleted file mode 100644 index 11364974..00000000 --- a/src/Psl/Iter/keys.php +++ /dev/null @@ -1,35 +0,0 @@ - 0, 'b' => 1, 'c' => 2]) - * => Iter('a', 'b', 'c') - * - * @template Tk - * @template Tv - * - * @param iterable $iterable Iterable to get keys from - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\keys instead. - * @see Vec\keys() - */ -function keys(iterable $iterable): Iterator -{ - return Iterator::from(static function () use ($iterable): Generator { - foreach ($iterable as $key => $_) { - yield $key; - } - }); -} diff --git a/src/Psl/Iter/map.php b/src/Psl/Iter/map.php deleted file mode 100644 index 797726c0..00000000 --- a/src/Psl/Iter/map.php +++ /dev/null @@ -1,42 +0,0 @@ - $i * 2); - * => Iter(2, 4, 6, 8, 10) - * - * @template Tk - * @template Tv - * @template T - * - * @param iterable $iterable Iterable to be mapped over - * @param (callable(Tv): T) $function - * - * @return Iterator - * - * @deprecated use `Dict\map` instead. - * @see Dict\map() - */ -function map(iterable $iterable, callable $function): Iterator -{ - return Iterator::from(static function () use ($iterable, $function): Generator { - foreach ($iterable as $key => $value) { - yield $key => $function($value); - } - }); -} diff --git a/src/Psl/Iter/map_keys.php b/src/Psl/Iter/map_keys.php deleted file mode 100644 index 32c90b69..00000000 --- a/src/Psl/Iter/map_keys.php +++ /dev/null @@ -1,42 +0,0 @@ - 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5], fn($i) => $i * 2); - * => Iter(0 => 1, 2 => 2, 4 => 3, 6 => 4, 8 => 5) - * - * @template Tk1 - * @template Tk2 - * @template Tv - * - * @param iterable $iterable Iterable to be mapped over - * @param (callable(Tk1): Tk2) $function - * - * @return Iterator - * - * @deprecated use `Dict\map_keys` instead. - * @see Dict\map_keys() - */ -function map_keys(iterable $iterable, callable $function): Iterator -{ - return Iterator::from(static function () use ($iterable, $function): Generator { - foreach ($iterable as $key => $value) { - yield $function($key) => $value; - } - }); -} diff --git a/src/Psl/Iter/map_with_key.php b/src/Psl/Iter/map_with_key.php deleted file mode 100644 index 7c34d044..00000000 --- a/src/Psl/Iter/map_with_key.php +++ /dev/null @@ -1,40 +0,0 @@ - $k + $v); - * => Iter(1, 3, 5, 7, 9) - * - * @template Tk - * @template Tv - * @template T - * - * @param iterable $iterable Iterable to be mapped over - * @param (callable(Tk,Tv): T) $function - * - * @return Iterator - * - * @deprecated use `Dict\map_with_key` instead. - * @see Dict\map_with_key() - */ -function map_with_key(iterable $iterable, callable $function): Iterator -{ - return Iterator::from(static function () use ($iterable, $function): Generator { - foreach ($iterable as $key => $value) { - yield $key => $function($key, $value); - } - }); -} diff --git a/src/Psl/Iter/merge.php b/src/Psl/Iter/merge.php deleted file mode 100644 index 833f093a..00000000 --- a/src/Psl/Iter/merge.php +++ /dev/null @@ -1,41 +0,0 @@ - Iter(0 => 1, 1 => 2, 0 => 9, 1 => 8) - * - * Iter\merge([0 => 1, 1 => 2], [2 => 9, 3 => 8]) - * => Iter(0 => 1, 1 => 2, 2 => 9, 3 => 8) - * - * @template Tk - * @template Tv - * - * @param iterable $first - * @param iterable ...$rest - * - * @return Iterator - * - * @deprecated use `Dict\merge` instead. - * @see Dict\merge() - * - * @no-named-arguments - */ -function merge(iterable $first, iterable ...$rest): Iterator -{ - $iterables = [$first]; - foreach ($rest as $iterable) { - $iterables[] = $iterable; - } - - /** @psalm-suppress DeprecatedFunction */ - return flatten($iterables); -} diff --git a/src/Psl/Iter/product.php b/src/Psl/Iter/product.php deleted file mode 100644 index f95ed927..00000000 --- a/src/Psl/Iter/product.php +++ /dev/null @@ -1,85 +0,0 @@ - Iter([0, 0] => [1, 3], [0, 1] => [1, 4], [1, 0] => [2, 3], [1, 1] => [2, 4]) - * - * @template Tk - * @template Tv - * - * @param iterable ...$iterables Iterables to combine - * - * @return Iterator, list> - * - * @deprecated ( no replacement is provided ) - */ -function product(iterable ...$iterables): Iterator -{ - return Iterator::from(static function () use ($iterables): Generator { - /** @var list> $iterators */ - $iterators = Vec\values(Dict\map( - $iterables, - static fn (iterable $iterable) => Iterator::create($iterable) - )); - - $numIterators = count($iterators); - if (0 === $numIterators) { - /** @var iterable, list> */ - yield [] => []; - - return; - } - - /** @var list $keyTuple */ - /** @var list $valueTuple */ - $keyTuple = Vec\fill($numIterators, null); - $valueTuple = Vec\fill($numIterators, null); - $i = -1; - while (true) { - while (++$i < $numIterators - 1) { - $iterators[$i]->rewind(); - // @codeCoverageIgnoreStart - if (!$iterators[$i]->valid()) { - return; - } - // @codeCoverageIgnoreEnd - - $keyTuple[$i] = $iterators[$i]->key(); - $valueTuple[$i] = $iterators[$i]->current(); - } - - foreach ($iterators[$i] as $keyTuple[$i] => $valueTuple[$i]) { - yield Vec\values($keyTuple) => Vec\values($valueTuple); - } - - while (--$i >= 0) { - $iterators[$i]->next(); - if ($iterators[$i]->valid()) { - $keyTuple[$i] = $iterators[$i]->key(); - $valueTuple[$i] = $iterators[$i]->current(); - continue 2; - } - } - - return; - } - }); -} diff --git a/src/Psl/Iter/pull.php b/src/Psl/Iter/pull.php deleted file mode 100644 index 11f0efbc..00000000 --- a/src/Psl/Iter/pull.php +++ /dev/null @@ -1,47 +0,0 @@ - Str\chr($i + 65), - * fn($i) => 2**$i, - * ) - * => Iter( - * 1 => 'A', 2 => 'B', 4 => 'C', 8 => 'D', 16 => 'E', 32 => 'F', - * 64 => 'G', 128 => 'H', 256 => 'I', 512 => 'J', 1024 => 'K' - * ) - * - * @template T - * @template Tk - * @template Tv - * - * @param iterable $iterable - * @param (callable(T): Tv) $value_func - * @param (callable(T): Tk) $key_func - * - * @return Iterator - * - * @deprecated use `Dict\pull` instead. - * @see Dict\pull() - */ -function pull(iterable $iterable, callable $value_func, callable $key_func): Iterator -{ - return Iterator::from(static function () use ($iterable, $value_func, $key_func): Generator { - foreach ($iterable as $value) { - yield $key_func($value) => $value_func($value); - } - }); -} diff --git a/src/Psl/Iter/pull_with_key.php b/src/Psl/Iter/pull_with_key.php deleted file mode 100644 index bb88800a..00000000 --- a/src/Psl/Iter/pull_with_key.php +++ /dev/null @@ -1,48 +0,0 @@ - Str\chr($v + $k + 65), - * fn($k, $v) => 2**($v+$k) - * ) - * => Iter( - * 1 => 'A', 4 => 'C', 16 => 'E', 64 => 'G', 256 => 'I', 1024 => 'K', - * 4096 => 'M', 16384 => 'O', 65536 => 'Q', 262144 => 'S', 1048576 => 'U' - * ) - * - * @template Tk1 - * @template Tv1 - * @template Tk2 - * @template Tv2 - * - * @param iterable $iterable - * @param (callable(Tk1, Tv1): Tv2) $value_func - * @param (callable(Tk1, Tv1): Tk2) $key_func - * - * @return Iterator - * - * @deprecated use `Dict\pull_with_key` instead. - * @see Dict\pull_with_key() - */ -function pull_with_key(iterable $iterable, callable $value_func, callable $key_func): Iterator -{ - return Iterator::from(static function () use ($iterable, $value_func, $key_func): Generator { - foreach ($iterable as $key => $value) { - yield $key_func($key, $value) => $value_func($key, $value); - } - }); -} diff --git a/src/Psl/Iter/random.php b/src/Psl/Iter/random.php index 78d1922f..9d7aa525 100644 --- a/src/Psl/Iter/random.php +++ b/src/Psl/Iter/random.php @@ -24,8 +24,7 @@ function random(iterable $iterable) { // We convert the iterable to an array before checking if it is empty, // this helps us avoids an issue when the iterable is a generator where - // would exhaust it when calling `is_empty`, which results in an - // exception at the `to_array` call. + // would exhaust it when calling `count` $values = Vec\values($iterable); $size = count($values); diff --git a/src/Psl/Iter/range.php b/src/Psl/Iter/range.php deleted file mode 100644 index cfa2b446..00000000 --- a/src/Psl/Iter/range.php +++ /dev/null @@ -1,95 +0,0 @@ - Iter(0, 1, 2, 3, 4, 5) - * - * Iter\range(5, 0) - * => Iter(5, 4, 3, 2, 1, 0) - * - * Iter\range(0.0, 3.0, 0.5) - * => Iter(0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0) - * - * Iter\range(3.0, 0.0, -0.5) - * => Iter(3.0, 2.5, 2.0, 1.5, 1.0, 0.5, 0.0) - * - * @template T of int|float - * - * @param T $start First number (inclusive) - * @param T $end Last number (inclusive, but doesn't have to be part of - * resulting range if $step steps over it) - * @param T|null $step Step between numbers (defaults to 1 if $start smaller - * $end and to -1 if $start greater $end) - * - * @throws Psl\Exception\InvariantViolationException If $start < $end, and $step is negative. - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\range instead. - * @see Vec\range($start, $end, $step) - */ -function range($start, $end, $step = null): Iterator -{ - if ($start < $end) { - Psl\invariant(null === $step || $step > 0, 'If start < end, the step must be positive.'); - } - - if ($start > $end) { - Psl\invariant(null === $step || $step < 0, 'If start > end, the step must be negative.'); - } - - return Iterator::from( - /** - * @return Generator - * - * @see https://github.com/vimeo/psalm/issues/2152#issuecomment-533363310 - * - * @psalm-suppress InvalidReturnType - * @psalm-suppress InvalidOperand - * @psalm-suppress DocblockTypeContradiction - */ - static function () use ($start, $end, $step): Generator { - if ((float) $start === (float) $end) { - yield $start; - } elseif ($start < $end) { - if (null === $step) { - /** @var T $step */ - $step = 1; - } - - Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - for ($i = $start; $i <= $end; $i += $step) { - Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.'); - Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - yield $i; - } - } else { - if (null === $step) { - /** @var T $step */ - $step = -1; - } - - Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - for ($i = $start; $i >= $end; $i += $step) { - Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.'); - Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - yield $i; - } - } - } - ); -} diff --git a/src/Psl/Iter/reduce.php b/src/Psl/Iter/reduce.php index 78d18d12..9f7b9532 100644 --- a/src/Psl/Iter/reduce.php +++ b/src/Psl/Iter/reduce.php @@ -29,7 +29,7 @@ * * @return Ts */ -function reduce(iterable $iterable, callable $function, $initial) +function reduce(iterable $iterable, callable $function, mixed $initial): mixed { $accumulator = $initial; foreach ($iterable as $v) { diff --git a/src/Psl/Iter/reduce_keys.php b/src/Psl/Iter/reduce_keys.php index 6665cc61..adf17004 100644 --- a/src/Psl/Iter/reduce_keys.php +++ b/src/Psl/Iter/reduce_keys.php @@ -25,12 +25,12 @@ * @template Ts * * @param iterable $iterable - * @param (callable(?Ts, Tk): Ts) $function - * @param Ts|null $initial + * @param (callable(Ts, Tk): Ts) $function + * @param Ts $initial * - * @return Ts|null + * @return Ts */ -function reduce_keys(iterable $iterable, callable $function, $initial = null) +function reduce_keys(iterable $iterable, callable $function, mixed $initial): mixed { $accumulator = $initial; foreach ($iterable as $k => $_v) { diff --git a/src/Psl/Iter/reduce_with_keys.php b/src/Psl/Iter/reduce_with_keys.php index 65a7aa01..89991e0b 100644 --- a/src/Psl/Iter/reduce_with_keys.php +++ b/src/Psl/Iter/reduce_with_keys.php @@ -32,12 +32,12 @@ * @template Ts * * @param iterable $iterable - * @param (callable(?Ts, Tk, Tv): Ts) $function - * @param Ts|null $initial + * @param (callable(Ts, Tk, Tv): Ts) $function + * @param Ts $initial * - * @return Ts|null + * @return Ts */ -function reduce_with_keys(iterable $iterable, callable $function, $initial = null) +function reduce_with_keys(iterable $iterable, callable $function, mixed $initial): mixed { $accumulator = $initial; foreach ($iterable as $k => $v) { diff --git a/src/Psl/Iter/reductions.php b/src/Psl/Iter/reductions.php deleted file mode 100644 index 1b8f1016..00000000 --- a/src/Psl/Iter/reductions.php +++ /dev/null @@ -1,42 +0,0 @@ - $iterable - * @param (callable(?Ts, Tk, Tv): Ts) $function - * @param Ts|null $initial - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\reductions instead. - * @see Vec\reductions() - */ -function reductions(iterable $iterable, callable $function, $initial = null): Iterator -{ - return Iterator::from(static function () use ($iterable, $function, $initial): Generator { - $accumulator = $initial; - foreach ($iterable as $k => $v) { - $accumulator = $function($accumulator, $k, $v); - yield $accumulator; - } - }); -} diff --git a/src/Psl/Iter/reindex.php b/src/Psl/Iter/reindex.php deleted file mode 100644 index c5fd1b0d..00000000 --- a/src/Psl/Iter/reindex.php +++ /dev/null @@ -1,50 +0,0 @@ - 42, 'name' => 'foo'], - * ['id' => 24, 'name' => 'bar'] - * ]; - * - * Iter\reindex($users, fn($user) => $user['id']) - * => Iter( - * 42 => ['id' => 42, 'name' => 'foo'], - * 24 => ['id' => 24, 'name' => 'bar'] - * ) - * - * @template Tk1 - * @template Tk2 - * @template Tv - * - * @param iterable $iterable Iterable to reindex - * @param (callable(Tv): Tk2) $function - * - * @return Iterator - * - * @deprecated use `Dict\reindex` instead. - * @see Dict\reindex() - */ -function reindex(iterable $iterable, callable $function): Iterator -{ - return Iterator::from(static function () use ($iterable, $function): Generator { - foreach ($iterable as $value) { - yield $function($value) => $value; - } - }); -} diff --git a/src/Psl/Iter/repeat.php b/src/Psl/Iter/repeat.php deleted file mode 100644 index f7f9b1df..00000000 --- a/src/Psl/Iter/repeat.php +++ /dev/null @@ -1,50 +0,0 @@ - Iter(42, 42, 42, 42, 42) - * - * Iter\repeat(1) - * => Iter(1, 1, 1, 1, 1, 1, 1, 1, 1, ...) - * - * @template T - * - * @param T $value Value to repeat - * @param int $num Number of repetitions (defaults to INF) - * - * @throws Psl\Exception\InvariantViolationException If $num is negative. - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\fill instead. - * @see Vec\fill() - */ -function repeat($value, ?int $num = null): Iterator -{ - Psl\invariant(null === $num || $num >= 0, 'Number of repetitions must be non-negative.'); - - return Iterator::from(static function () use ($value, $num): Generator { - if (null === $num) { - /** @var int $num */ - $num = Math\INFINITY; - } - - for ($i = 0; $i < $num; ++$i) { - yield $value; - } - }); -} diff --git a/src/Psl/Iter/reproduce.php b/src/Psl/Iter/reproduce.php deleted file mode 100644 index a3e19376..00000000 --- a/src/Psl/Iter/reproduce.php +++ /dev/null @@ -1,44 +0,0 @@ - Iter(1, 2, 3, 4, 5) - * - * @template T - * - * @param (callable(int): T) $factory - * @param int|null $number How many times should the factory be executed? - * - * @throws Psl\Exception\InvariantViolationException If $number < 1 - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\reproduce instead. - * @see Vec\reproduce() - */ -function reproduce(callable $factory, ?int $number = null): Iterator -{ - /** @var int $max */ - $max = $number ?? Math\INFINITY; - Psl\invariant($max >= 1, 'The number of times you want to reproduce must be at least 1.'); - - return Iterator::from(static function () use ($max, $factory): Generator { - for ($current = 1; $current <= $max; $current++) { - yield $factory($current); - } - }); -} diff --git a/src/Psl/Iter/reverse.php b/src/Psl/Iter/reverse.php deleted file mode 100644 index 1774bf72..00000000 --- a/src/Psl/Iter/reverse.php +++ /dev/null @@ -1,40 +0,0 @@ - Iter('qux', 'baz', 'bar', 'foo') - * - * @template T - * - * @param iterable $iterable The iterable to reverse. - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\reverse instead. - * @see Vec\reverse() - */ -function reverse(iterable $iterable): Iterator -{ - return Iterator::from(static function () use ($iterable): Generator { - $values = Vec\values($iterable); - $size = namespace\count($values); - - if (0 === $size) { - return; - } - - for ($i = $size - 1; $i >= 0; $i--) { - yield $values[$i]; - } - }); -} diff --git a/src/Psl/Iter/slice.php b/src/Psl/Iter/slice.php deleted file mode 100644 index 48f34613..00000000 --- a/src/Psl/Iter/slice.php +++ /dev/null @@ -1,59 +0,0 @@ - Iter(0, 1, 2, 3, 4, 5) - * - * Iter\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5, 3) - * => Iter(0, 1, 2) - * - * @template Tk - * @template Tv - * - * @param iterable $iterable Iterable to take the slice from - * @param int $start Start offset - * @param int $length Length (if not specified all remaining values from the iterable are used) - * - * @throws Psl\Exception\InvariantViolationException If the $start offset or $length are negative - * - * @return Iterator - * - * @deprecated use `Dict\slice` instead. - * @see Dict\slice() - */ -function slice(iterable $iterable, int $start, ?int $length = null): Iterator -{ - Psl\invariant($start >= 0, 'Start offset must be non-negative.'); - Psl\invariant(null === $length || $length >= 0, 'Length must be non-negative.'); - - return Iterator::from(static function () use ($iterable, $start, $length): Generator { - if (0 === $length) { - /** @psalm-suppress InvalidReturnStatement */ - return; - } - - $i = 0; - foreach ($iterable as $key => $value) { - if ($i++ < $start) { - continue; - } - - yield $key => $value; - if (null !== $length && $i >= $start + $length) { - break; - } - } - }); -} diff --git a/src/Psl/Iter/take.php b/src/Psl/Iter/take.php deleted file mode 100644 index 36250f6c..00000000 --- a/src/Psl/Iter/take.php +++ /dev/null @@ -1,29 +0,0 @@ - $iterable - * - * @throws Psl\Exception\InvariantViolationException If the $n is negative - * - * @return Iterator - * - * @deprecated use `Dict\take` instead. - * @see Dict\take() - */ -function take(iterable $iterable, int $n): Iterator -{ - /** @psalm-suppress DeprecatedFunction */ - return slice($iterable, 0, $n); -} diff --git a/src/Psl/Iter/take_while.php b/src/Psl/Iter/take_while.php deleted file mode 100644 index 2daebbf3..00000000 --- a/src/Psl/Iter/take_while.php +++ /dev/null @@ -1,43 +0,0 @@ - $i > 0) - * => Iter(3, 1, 4) - * - * @template Tk - * @template Tv - * - * @param iterable $iterable Iterable to take values from - * @param (callable(Tv): bool) $predicate - * - * @return Iterator - * - * @deprecated use `Dict\take_while` instead. - * @see Dict\take_while() - */ -function take_while(iterable $iterable, callable $predicate): Iterator -{ - return Iterator::from(static function () use ($iterable, $predicate): Generator { - foreach ($iterable as $key => $value) { - if (!$predicate($value)) { - return; - } - - yield $key => $value; - } - }); -} diff --git a/src/Psl/Iter/to_array.php b/src/Psl/Iter/to_array.php deleted file mode 100644 index 1cc71721..00000000 --- a/src/Psl/Iter/to_array.php +++ /dev/null @@ -1,29 +0,0 @@ - $iterable - * - * @return list - * - * @deprecated since 1.2, use Vec\values instead. - * @see Vec\values() - */ -function to_array(iterable $iterable): array -{ - $result = []; - foreach ($iterable as $value) { - $result[] = $value; - } - - return $result; -} diff --git a/src/Psl/Iter/to_array_with_keys.php b/src/Psl/Iter/to_array_with_keys.php deleted file mode 100644 index 12776187..00000000 --- a/src/Psl/Iter/to_array_with_keys.php +++ /dev/null @@ -1,30 +0,0 @@ - $iterable - * - * @return array - * - * @deprecated use `Dict\from_iterable` instead. - * @see Dict\from_iterable() - */ -function to_array_with_keys(iterable $iterable): array -{ - $result = []; - foreach ($iterable as $key => $value) { - $result[$key] = $value; - } - - return $result; -} diff --git a/src/Psl/Iter/to_iterator.php b/src/Psl/Iter/to_iterator.php index d6760c6c..983bffe8 100644 --- a/src/Psl/Iter/to_iterator.php +++ b/src/Psl/Iter/to_iterator.php @@ -14,7 +14,7 @@ * * @return Iterator * - * @see Iterator + * @see Iterator */ function to_iterator(iterable $iterable): Iterator { diff --git a/src/Psl/Iter/values.php b/src/Psl/Iter/values.php deleted file mode 100644 index b045c8df..00000000 --- a/src/Psl/Iter/values.php +++ /dev/null @@ -1,39 +0,0 @@ - 'foo', 'b' => 'bar', 'c' => 'baz']) - * => Iter('foo', 'bar', 'baz') - * - * Iter\values([17 => 1, 42 => 2, -2 => 100]) - * => Iter(1, 42, 100) - * - * @template Tk - * @template Tv - * - * @param iterable $iterable Iterable to get values from - * - * @return Iterator - * - * @deprecated since 1.2, use Vec\values instead. - * @see Vec\values() - */ -function values(iterable $iterable): Iterator -{ - return Iterator::from(static function () use ($iterable): Generator { - foreach ($iterable as $value) { - yield $value; - } - }); -} diff --git a/src/Psl/Iter/zip.php b/src/Psl/Iter/zip.php deleted file mode 100644 index 369ba093..00000000 --- a/src/Psl/Iter/zip.php +++ /dev/null @@ -1,82 +0,0 @@ - Iter( - * Arr(0, 0, 0) => Arr(1, 4, 7), - * Arr(1, 1, 1) => Arr(2, 5, 8), - * Arr(2, 2, 2) => Arr(3, 6, 9) - * ) - * - * @template Tk - * @template Tv - * - * @param iterable ...$iterables - * - * @return Iterator, list> - * - * @deprecated since 1.2, use Vec\zip instead. - * @see Vec\zip() - */ -function zip(iterable ...$iterables): Iterator -{ - return Iterator::from(static function () use ($iterables): Generator { - if (0 === count($iterables)) { - return; - } - - $iterators = Vec\values(Dict\map( - $iterables, - /** - * @param iterable $iterable - * - * @return Iterator - */ - static fn ($iterable) => new Iterator((static fn () => yield from $iterable)()), - )); - - apply($iterators, static fn (Iterator $iterator) => $iterator->rewind()); - while (all($iterators, static fn (Iterator $iterator) => $iterator->valid())) { - $keys = Vec\values(Dict\map( - $iterators, - /** - * @param Iterator $iterator - * - * @return Tk - */ - static fn (Iterator $iterator) => $iterator->key(), - )); - - $values = Vec\values(Dict\map( - $iterators, - /** - * @param Iterator $iterator - * - * @return Tv - */ - static fn (Iterator $iterator) => $iterator->current(), - )); - - yield $keys => $values; - - apply($iterators, static fn (Iterator $iterator) => $iterator->next()); - } - }); -} diff --git a/src/Psl/Type/is_array.php b/src/Psl/Type/is_array.php deleted file mode 100644 index 2db0fa3b..00000000 --- a/src/Psl/Type/is_array.php +++ /dev/null @@ -1,21 +0,0 @@ - $var - * - * @pure - * - * @deprecated use `Type\dict($kt, $vt)->matches($value)` instead. - */ -function is_array(mixed $var): bool -{ - return php_is_array($var); -} diff --git a/src/Psl/Type/is_arraykey.php b/src/Psl/Type/is_arraykey.php deleted file mode 100644 index 6715951a..00000000 --- a/src/Psl/Type/is_arraykey.php +++ /dev/null @@ -1,23 +0,0 @@ -matches($value)` instead. - */ -function is_arraykey(mixed $key): bool -{ - /** - * @psalm-suppress ImpureFunctionCall - * @psalm-suppress ImpureMethodCall - */ - return array_key()->matches($key); -} diff --git a/src/Psl/Type/is_bool.php b/src/Psl/Type/is_bool.php deleted file mode 100644 index c191116c..00000000 --- a/src/Psl/Type/is_bool.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($value)` instead. - */ -function is_bool(mixed $var): bool -{ - return php_is_bool($var); -} diff --git a/src/Psl/Type/is_callable.php b/src/Psl/Type/is_callable.php deleted file mode 100644 index fa50a7aa..00000000 --- a/src/Psl/Type/is_callable.php +++ /dev/null @@ -1,19 +0,0 @@ -matches($value)` instead. - */ -function is_float(mixed $var): bool -{ - return php_is_float($var); -} diff --git a/src/Psl/Type/is_instanceof.php b/src/Psl/Type/is_instanceof.php deleted file mode 100644 index 520a8b02..00000000 --- a/src/Psl/Type/is_instanceof.php +++ /dev/null @@ -1,25 +0,0 @@ - $class - * - * @psalm-assert-if-true T $object - * - * @pure - * - * @deprecated use `Type\object($class)->matches($object)` instead. - */ -function is_instanceof(object $object, string $class): bool -{ - return is_a($object, $class, false); -} diff --git a/src/Psl/Type/is_int.php b/src/Psl/Type/is_int.php deleted file mode 100644 index e66bec79..00000000 --- a/src/Psl/Type/is_int.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($value)` instead. - */ -function is_int(mixed $var): bool -{ - return php_is_int($var); -} diff --git a/src/Psl/Type/is_iterable.php b/src/Psl/Type/is_iterable.php deleted file mode 100644 index bab9bc3e..00000000 --- a/src/Psl/Type/is_iterable.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($value)` instead. - */ -function is_iterable(mixed $var): bool -{ - return php_is_iterable($var); -} diff --git a/src/Psl/Type/is_null.php b/src/Psl/Type/is_null.php deleted file mode 100644 index da222901..00000000 --- a/src/Psl/Type/is_null.php +++ /dev/null @@ -1,19 +0,0 @@ -matches($value)` instead. - */ -function is_null(mixed $var): bool -{ - return null === $var; -} diff --git a/src/Psl/Type/is_numeric.php b/src/Psl/Type/is_numeric.php deleted file mode 100644 index 586de4eb..00000000 --- a/src/Psl/Type/is_numeric.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($value)` instead. - */ -function is_numeric(mixed $var): bool -{ - return php_is_numeric($var); -} diff --git a/src/Psl/Type/is_object.php b/src/Psl/Type/is_object.php deleted file mode 100644 index bc8a6f0d..00000000 --- a/src/Psl/Type/is_object.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($var)` instead. - */ -function is_object(mixed $var): bool -{ - return php_is_object($var); -} diff --git a/src/Psl/Type/is_resource.php b/src/Psl/Type/is_resource.php deleted file mode 100644 index c918cdd6..00000000 --- a/src/Psl/Type/is_resource.php +++ /dev/null @@ -1,23 +0,0 @@ -assert($var)` instead. - * - * @psalm-assert-if-true resource $var - * - * @pure - * - * @deprecated use `Type\resource($type)->matches($value)` instead. - */ -function is_resource(mixed $var): bool -{ - return php_is_resource($var); -} diff --git a/src/Psl/Type/is_scalar.php b/src/Psl/Type/is_scalar.php deleted file mode 100644 index 7b91754f..00000000 --- a/src/Psl/Type/is_scalar.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($value)` instead. - */ -function is_scalar(mixed $var): bool -{ - return php_is_scalar($var); -} diff --git a/src/Psl/Type/is_string.php b/src/Psl/Type/is_string.php deleted file mode 100644 index 6847200a..00000000 --- a/src/Psl/Type/is_string.php +++ /dev/null @@ -1,21 +0,0 @@ -matches($value)` instead. - */ -function is_string(mixed $var): bool -{ - return php_is_string($var); -} diff --git a/tests/unit/Arr/AtTest.php b/tests/unit/Arr/AtTest.php deleted file mode 100644 index b2c18419..00000000 --- a/tests/unit/Arr/AtTest.php +++ /dev/null @@ -1,38 +0,0 @@ - 4, 'b' => 5], 'b'], - [0, [0, 1], 0], - [1, [1, 2], 0], - [null, [null], 0], - ]; - } - - public function testAtThrowsForOutOfBoundKey(): void - { - $this->expectException(Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Key (5) is out-of-bounds.'); - - Arr\at([], 5); - } -} diff --git a/tests/unit/Arr/ConcatTest.php b/tests/unit/Arr/ConcatTest.php deleted file mode 100644 index 49a44a51..00000000 --- a/tests/unit/Arr/ConcatTest.php +++ /dev/null @@ -1,41 +0,0 @@ - 'a'], - ['bar' => 'b'], - ['baz' => 'c'], - ], - [ - ['foo', 'bar', 'baz', 'qux'], - ['foo'], - ['bar'], - ['baz', 'qux'], - ], - [ - [1, 2, 3], - [1, 2, 3], - ], - ]; - } -} diff --git a/tests/unit/Arr/ContainsKeyTest.php b/tests/unit/Arr/ContainsKeyTest.php deleted file mode 100644 index b06a6a0f..00000000 --- a/tests/unit/Arr/ContainsKeyTest.php +++ /dev/null @@ -1,28 +0,0 @@ - null], 'foo'], - [true, [1], 0], - ]; - } -} diff --git a/tests/unit/Arr/ContainsTest.php b/tests/unit/Arr/ContainsTest.php deleted file mode 100644 index 6b2efb76..00000000 --- a/tests/unit/Arr/ContainsTest.php +++ /dev/null @@ -1,29 +0,0 @@ - 1], - ['foo'], - ], - [ - ['foo' => 2, 'bar' => 1, 'baz' => 5], - ['foo', 'bar', 'baz', 'foo', 'baz', 'baz', 'baz', 'baz'], - ], - [ - ['foo' => 2, 'bar' => 1, 'baz' => 4], - Arr\concat( - ['foo', 'bar', 'baz'], - ['foo'], - ['baz'], - ['baz', 'baz'], - ), - ], - ]; - } -} diff --git a/tests/unit/Arr/DropTest.php b/tests/unit/Arr/DropTest.php deleted file mode 100644 index b4e28610..00000000 --- a/tests/unit/Arr/DropTest.php +++ /dev/null @@ -1,29 +0,0 @@ - 4, 4 => 5], [1, 2, 3, 4, 5], 3]; - yield [[2 => 3, 3 => 4, 4 => 5], [1, 2, 3, 4, 5], 2]; - yield [[], [1, 2, 3, 4, 5], 5]; - } -} diff --git a/tests/unit/Arr/DropWhileTest.php b/tests/unit/Arr/DropWhileTest.php deleted file mode 100644 index 97a80168..00000000 --- a/tests/unit/Arr/DropWhileTest.php +++ /dev/null @@ -1,29 +0,0 @@ - false]; - yield [[3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 3]; - yield [[2 => 3, 3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 2]; - yield [[], [1, 2, 3, 4, 5], static fn (int $_) => true]; - } -} diff --git a/tests/unit/Arr/FillTest.php b/tests/unit/Arr/FillTest.php deleted file mode 100644 index 586d900d..00000000 --- a/tests/unit/Arr/FillTest.php +++ /dev/null @@ -1,59 +0,0 @@ - true, 6 => true, 7 => true], - true, - 5, - 3, - ], - - [ - [8 => null, 9 => null, 10 => null], - null, - 8, - 3, - ], - ]; - } -} diff --git a/tests/unit/Arr/FilterKeysTest.php b/tests/unit/Arr/FilterKeysTest.php deleted file mode 100644 index 438c042b..00000000 --- a/tests/unit/Arr/FilterKeysTest.php +++ /dev/null @@ -1,30 +0,0 @@ - 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn () => false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $k): bool => 1 !== $k]; - } -} diff --git a/tests/unit/Arr/FilterNullsTest.php b/tests/unit/Arr/FilterNullsTest.php deleted file mode 100644 index a885e88e..00000000 --- a/tests/unit/Arr/FilterNullsTest.php +++ /dev/null @@ -1,20 +0,0 @@ - false]; - yield [['a', 'b'], ['a', 'b'], static fn (string $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (string $v): bool => 'b' !== $v]; - } -} diff --git a/tests/unit/Arr/FilterWithKeyTest.php b/tests/unit/Arr/FilterWithKeyTest.php deleted file mode 100644 index d06ebacd..00000000 --- a/tests/unit/Arr/FilterWithKeyTest.php +++ /dev/null @@ -1,34 +0,0 @@ - false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_k, string $_v): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 0 !== $k]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 1 !== $k]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 1 !== $k]; - yield [[1 => 'b'], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 0 !== $k]; - } -} diff --git a/tests/unit/Arr/FirstKeyTest.php b/tests/unit/Arr/FirstKeyTest.php deleted file mode 100644 index e6a263d0..00000000 --- a/tests/unit/Arr/FirstKeyTest.php +++ /dev/null @@ -1,44 +0,0 @@ - 'foo'], - ], - - [ - 'bar', - ['bar' => 'baz', 'baz' => 'qux'], - ], - ]; - } -} diff --git a/tests/unit/Arr/FirstTest.php b/tests/unit/Arr/FirstTest.php deleted file mode 100644 index b5b2f6f2..00000000 --- a/tests/unit/Arr/FirstTest.php +++ /dev/null @@ -1,40 +0,0 @@ -expectException(Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Expected a non-empty array.'); - - Arr\firstx([]); - } -} diff --git a/tests/unit/Arr/FlatMapTest.php b/tests/unit/Arr/FlatMapTest.php deleted file mode 100644 index 60eaa097..00000000 --- a/tests/unit/Arr/FlatMapTest.php +++ /dev/null @@ -1,36 +0,0 @@ - [$v]]; - yield [[1, 2, 2, 4, 3, 6], [1, 2, 3], static fn (int $v): array => [$v, $v * 2]]; - yield [[], [1, 2], static fn (int $k): array => []]; - yield [[[1], [2]], [1, 2], static fn (int $v): array => [[$v]]]; - yield [[], [], static fn (int $k): array => []]; - yield [ - ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog', ''], - ['The quick brown', 'fox', 'jumps over', 'the lazy dog', ''], - static fn (string $v): array => Str\Split($v, ' ') - ]; - } -} diff --git a/tests/unit/Arr/FlattenTest.php b/tests/unit/Arr/FlattenTest.php deleted file mode 100644 index 9b8d0860..00000000 --- a/tests/unit/Arr/FlattenTest.php +++ /dev/null @@ -1,44 +0,0 @@ - 'b', 'b' => 'c', 'c' => 'd', 'd' => 'e'], - - [ - ['a' => 'foo', 'b' => 'bar'], - ['a' => 'b'], - ['b' => 'c', 'c' => 'd'], - ['d' => 'baz'], - ['d' => 'e'], - ], - ], - - [ - [1, 2, 9, 8], - [ - [0 => 1, 1 => 2], - [2 => 9, 3 => 8], - ], - ], - ]; - } -} diff --git a/tests/unit/Arr/FlipTest.php b/tests/unit/Arr/FlipTest.php deleted file mode 100644 index 5b822410..00000000 --- a/tests/unit/Arr/FlipTest.php +++ /dev/null @@ -1,45 +0,0 @@ - 'b', 'b' => 'c', 'c' => 'd'], - ['b' => 'a', 'c' => 'b', 'd' => 'c'], - ], - - [ - [1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 4, 6 => 5, 7 => 6, 8 => 7, 9 => 8, 10 => 9], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - ], - ]; - } - - public function testFlipThrowsForNonArrayKeyValues(): void - { - $this->expectException(Exception\InvariantViolationException::class); - $this->expectExceptionMessage( - 'Expected all values to be of type array-key, value of type (resource) provided.' - ); - - Arr\flip([STDOUT]); - } -} diff --git a/tests/unit/Arr/IdxTest.php b/tests/unit/Arr/IdxTest.php deleted file mode 100644 index 370ffc9e..00000000 --- a/tests/unit/Arr/IdxTest.php +++ /dev/null @@ -1,28 +0,0 @@ - null], 'foo', 'bar'], - [1, [1], 0, 2], - ]; - } -} diff --git a/tests/unit/Arr/KeysTest.php b/tests/unit/Arr/KeysTest.php deleted file mode 100644 index 79c9646d..00000000 --- a/tests/unit/Arr/KeysTest.php +++ /dev/null @@ -1,31 +0,0 @@ - 'bar', - 'bar' => 'baz', - 'baz' => 'qux', - ]; - - $keys = Arr\keys($array); - - static::assertSameSize($keys, $array); - static::assertSame($keys, array_keys($array)); - - foreach ($array as $key => $value) { - static::assertTrue(Arr\contains($keys, $key)); - } - } -} diff --git a/tests/unit/Arr/LastKeyTest.php b/tests/unit/Arr/LastKeyTest.php deleted file mode 100644 index fcf431a0..00000000 --- a/tests/unit/Arr/LastKeyTest.php +++ /dev/null @@ -1,44 +0,0 @@ - 'foo', 2 => 'bar'], - ], - - [ - 'baz', - ['bar' => 'baz', 'baz' => 'qux'], - ], - ]; - } -} diff --git a/tests/unit/Arr/LastTest.php b/tests/unit/Arr/LastTest.php deleted file mode 100644 index 0cbf6501..00000000 --- a/tests/unit/Arr/LastTest.php +++ /dev/null @@ -1,40 +0,0 @@ -expectException(Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Expected a non-empty array.'); - - Arr\lastx([]); - } -} diff --git a/tests/unit/Arr/MapKeysTest.php b/tests/unit/Arr/MapKeysTest.php deleted file mode 100644 index 49abfd49..00000000 --- a/tests/unit/Arr/MapKeysTest.php +++ /dev/null @@ -1,29 +0,0 @@ - $k]; - yield [[1, 2 => 2, 4 => 3], [1, 2, 3], static fn (int $k): int => $k * 2]; - yield [['0' => 1, '1' => 2, '2' => 3], [1, 2, 3], static fn (int $k): string => (string) $k]; - yield [[], [], static fn (int $k): string => (string) $k]; - } -} diff --git a/tests/unit/Arr/MapTest.php b/tests/unit/Arr/MapTest.php deleted file mode 100644 index f82e2653..00000000 --- a/tests/unit/Arr/MapTest.php +++ /dev/null @@ -1,29 +0,0 @@ - $v]; - yield [[2, 4, 6], [1, 2, 3], static fn (int $v): int => $v * 2]; - yield [['1', '2', '3'], [1, 2, 3], static fn (int $v): string => (string)$v]; - yield [[], [], static fn (int $k): string => (string)$v]; - } -} diff --git a/tests/unit/Arr/MapWithKeyTest.php b/tests/unit/Arr/MapWithKeyTest.php deleted file mode 100644 index cb9c40a6..00000000 --- a/tests/unit/Arr/MapWithKeyTest.php +++ /dev/null @@ -1,29 +0,0 @@ - $k + $v]; - yield [[0, 4, 16], [1, 2, 3], static fn (int $k, int $v): int => $k * (2 ** $v)]; - yield [['1', '3', '5'], [1, 2, 3], static fn (int $k, int $v): string => (string) ($k + $v)]; - yield [[], [], static fn (int $k, int $v): string => (string) ($k + $v)]; - } -} diff --git a/tests/unit/Arr/MergeTest.php b/tests/unit/Arr/MergeTest.php deleted file mode 100644 index 33677ecc..00000000 --- a/tests/unit/Arr/MergeTest.php +++ /dev/null @@ -1,40 +0,0 @@ - 'b', 'b' => 'c', 'c' => 'd', 'd' => 'e'], - - ['a' => 'foo', 'b' => 'bar'], - ['a' => 'b'], - ['b' => 'c', 'c' => 'd'], - ['d' => 'baz'], - ['d' => 'e'], - ], - - [ - [1, 2, 9, 8], - [0 => 1, 1 => 2], - [2 => 9, 3 => 8], - ], - ]; - } -} diff --git a/tests/unit/Arr/PartitionTest.php b/tests/unit/Arr/PartitionTest.php deleted file mode 100644 index b80daeed..00000000 --- a/tests/unit/Arr/PartitionTest.php +++ /dev/null @@ -1,55 +0,0 @@ - Str\starts_with($str, 'b'), - ], - - [ - [['bar', 'baz'], ['foo', 'qux']], - ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => Str\starts_with($str, 'b'), - ], - - [ - [[], []], - [], - static fn ($_) => false, - ], - - [ - [[], ['foo', 'bar', 'baz', 'qux']], - ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => false, - ], - - [ - [['foo', 'bar', 'baz', 'qux'], []], - ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => true, - ], - ]; - } -} diff --git a/tests/unit/Arr/RandomTest.php b/tests/unit/Arr/RandomTest.php deleted file mode 100644 index 57048a0f..00000000 --- a/tests/unit/Arr/RandomTest.php +++ /dev/null @@ -1,37 +0,0 @@ -expectException(Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Expected a non-empty iterable.'); - - Arr\random([]); - } -} diff --git a/tests/unit/Arr/ShuffleTest.php b/tests/unit/Arr/ShuffleTest.php deleted file mode 100644 index 786e566d..00000000 --- a/tests/unit/Arr/ShuffleTest.php +++ /dev/null @@ -1,29 +0,0 @@ - 'bar', - 'bar' => 'baz', - 'baz' => 'qux', - ]; - - $shuffled = Arr\shuffle($array); - - static::assertSameSize($shuffled, $array); - static::assertNotSame($shuffled, $array); - - foreach ($shuffled as $value) { - static::assertTrue(Arr\contains($array, $value)); - } - } -} diff --git a/tests/unit/Arr/SliceTest.php b/tests/unit/Arr/SliceTest.php deleted file mode 100644 index 7bc9f07a..00000000 --- a/tests/unit/Arr/SliceTest.php +++ /dev/null @@ -1,49 +0,0 @@ - 0, 6 => 1, 7 => 2, 8 => 3, 9 => 4, 10 => 5], $result); - } - - public function testSliceWithLength(): void - { - $result = Arr\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5, 3); - - static::assertSame([5 => 0, 6 => 1, 7 => 2], $result); - } - - public function testSliceWithZeroLength(): void - { - $result = Arr\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5, 0); - - static::assertSame([], $result); - } - - public function testSliceThrowsIfStartIsNegative(): void - { - $this->expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Start offset must be non-negative.'); - - Arr\slice([1, 2, 3], -3); - } - - public function testSliceThrowsIfLengthIsNegative(): void - { - $this->expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Length must be non-negative.'); - - Arr\slice([1, 2, 3], 1, -3); - } -} diff --git a/tests/unit/Arr/SortWithKeysByTest.php b/tests/unit/Arr/SortWithKeysByTest.php deleted file mode 100644 index bf8531a8..00000000 --- a/tests/unit/Arr/SortWithKeysByTest.php +++ /dev/null @@ -1,112 +0,0 @@ - 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'qux', 'e' => 'lax']; - $expected = [2 => $a, 0 => $b, 1 => $c]; - $array = [$b, $c, $a]; - $scalar_fun = static fn ($arr) => Arr\count($arr); - - return [ - [ - $expected, - $array, - $scalar_fun, - ], - - [ - [1 => 'a', 2 => 'b', 3 => 'c', 0 => 'd'], - ['d', 'a', 'b', 'c'], - /** - * @param string $v - * - * @return string - * - * @psalm-pure - */ - static fn ($v) => $v, - ], - - [ - ['a'], - ['a'], - /** - * @param string $v - * - * @return string - * - * @psalm-pure - */ - static fn ($v) => $v, - ], - - [ - [0 => 'd', 3 => 'c', 2 => 'b', 1 => 'a'], - ['d', 'a', 'b', 'c'], - /** - * @param string $v - * - * @return string - * - * @psalm-pure - */ - static fn ($v) => $v, - /** - * @param string $a - * @param string $b - * - * @return int - * - * @psalm-pure - */ - static fn (string $a, string $b) => Str\ord($a) > Str\ord($b) ? -1 : 1, - ], - - [ - ['foo' => 'bar', 'baz' => 'qux'], - ['foo' => 'bar', 'baz' => 'qux'], - /** - * @param string $v - * - * @return string - * - * @psalm-pure - */ - static fn ($v) => $v, - ], - - [ - [4 => 'jumped', 0 => 'the', 1 => 'quick', 2 => 'brown', 3 => 'fox'], - ['the', 'quick', 'brown', 'fox', 'jumped'], - /** - * @param string $v - * - * @return string - * - * @psalm-pure - */ - static fn ($v) => Str\Byte\reverse($v), - ], - ]; - } -} diff --git a/tests/unit/Arr/SortWithKeysTest.php b/tests/unit/Arr/SortWithKeysTest.php deleted file mode 100644 index 3ff138f1..00000000 --- a/tests/unit/Arr/SortWithKeysTest.php +++ /dev/null @@ -1,40 +0,0 @@ - 'a', 2 => 'b', 0 => 'c'], - ['c', 'a', 'b'], - ], - - [ - [8, 9, 10], - [8, 9, 10], - static fn (int $a, int $b) => $a <=> $b ? -1 : 1, - ], - - [ - ['foo' => 'bar', 'bar' => 'baz'], - ['foo' => 'bar', 'bar' => 'baz'], - ], - ]; - } -} diff --git a/tests/unit/Arr/TakeTest.php b/tests/unit/Arr/TakeTest.php deleted file mode 100644 index 667a5518..00000000 --- a/tests/unit/Arr/TakeTest.php +++ /dev/null @@ -1,27 +0,0 @@ -expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Length must be non-negative.'); - - Arr\take([1, 2, 3], -3); - } -} diff --git a/tests/unit/Arr/TakeWhileTest.php b/tests/unit/Arr/TakeWhileTest.php deleted file mode 100644 index f4f1578a..00000000 --- a/tests/unit/Arr/TakeWhileTest.php +++ /dev/null @@ -1,29 +0,0 @@ - false]; - yield [[1, 2, 3], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 3]; - yield [[1, 2], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 2]; - yield [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], static fn (int $_) => true]; - } -} diff --git a/tests/unit/Arr/UniqueByTest.php b/tests/unit/Arr/UniqueByTest.php deleted file mode 100644 index 764fd9a5..00000000 --- a/tests/unit/Arr/UniqueByTest.php +++ /dev/null @@ -1,37 +0,0 @@ - 'a', 4 => 'saif'], - ['a', 'b', 'c', 'd', 'saif', 'jack'], - static fn (string $value): int => Str\length($value), - ], - - [ - [0 => 'foo', 2 => 'bar', 4 => '@baz'], - ['foo', '@foo', 'bar', '@bar', '@baz'], - static fn (string $value): string => Str\replace($value, '@', ''), - ], - ]; - } -} diff --git a/tests/unit/Arr/UniqueTest.php b/tests/unit/Arr/UniqueTest.php deleted file mode 100644 index edf6def1..00000000 --- a/tests/unit/Arr/UniqueTest.php +++ /dev/null @@ -1,37 +0,0 @@ - 'bar', - 'bar' => 'baz', - 'baz' => 'qux', - ]; - - $values = Arr\values($array); - - static::assertSameSize($values, $array); - static::assertSame($values, array_values($array)); - - foreach ($array as $value) { - static::assertTrue(Arr\contains($values, $value)); - } - } -} diff --git a/tests/unit/Arr/EqualTest.php b/tests/unit/Dict/EqualTest.php similarity index 89% rename from tests/unit/Arr/EqualTest.php rename to tests/unit/Dict/EqualTest.php index 818a02f2..5eea1b76 100644 --- a/tests/unit/Arr/EqualTest.php +++ b/tests/unit/Dict/EqualTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Psl\Tests\Unit\Arr; +namespace Psl\Tests\Unit\Dict; use PHPUnit\Framework\TestCase; -use Psl\Arr; use Psl\Collection; +use Psl\Dict; final class EqualTest extends TestCase { @@ -15,7 +15,7 @@ final class EqualTest extends TestCase */ public function testEqualReturnsTheExpectedValue(bool $expected, array $array, array $other): void { - static::assertSame($expected, Arr\equal($array, $other)); + static::assertSame($expected, Dict\equal($array, $other)); } public function provideData(): array diff --git a/tests/unit/Dict/FlipTest.php b/tests/unit/Dict/FlipTest.php new file mode 100644 index 00000000..ab89dd90 --- /dev/null +++ b/tests/unit/Dict/FlipTest.php @@ -0,0 +1,21 @@ + 'x', 'b' => 'y']); + + $result = Dict\flip($iterable); + + static::assertSame(['x' => 'a', 'y' => 'b'], $result); + } +} diff --git a/tests/unit/Arr/GroupByTest.php b/tests/unit/Dict/GroupByTest.php similarity index 80% rename from tests/unit/Arr/GroupByTest.php rename to tests/unit/Dict/GroupByTest.php index 7ff569e8..330e57b0 100644 --- a/tests/unit/Arr/GroupByTest.php +++ b/tests/unit/Dict/GroupByTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace Psl\Tests\Unit\Arr; +namespace Psl\Tests\Unit\Dict; use PHPUnit\Framework\TestCase; -use Psl\Arr; use Psl\Collection; +use Psl\Dict; use Psl\Exception; use Psl\Str; @@ -17,7 +17,7 @@ final class GroupByTest extends TestCase */ public function testGroupBy(array $expected, array $values, callable $callable): void { - static::assertSame($expected, Arr\group_by($values, $callable)); + static::assertSame($expected, Dict\group_by($values, $callable)); } public function provideData(): array @@ -36,8 +36,8 @@ public function provideData(): array ], [ - ['username' => ['@azjezz', '@fabpot', '@blacksun'], 'name' => ['Saif Eddin', 'Fabien', 'Gabrielle']], - ['@azjezz', 'Saif Eddin', '@fabpot', 'Fabien', '@blacksun', 'Gabrielle'], + ['username' => ['@azjezz', '@veewee', '@ocramius'], 'name' => ['Saif', 'Toon', 'Marco']], + ['@azjezz', 'Saif', '@veewee', 'Toon', '@ocramius', 'Marco'], static fn ($name) => Str\starts_with($name, '@') ? 'username' : 'name', ], ]; @@ -50,7 +50,7 @@ public function testGroupByThrowsWhenKeyFunReturnsNonArrayKey(): void 'Expected $key_func to return a value of type array-key, value of type (object) returned.' ); - Arr\group_by( + Dict\group_by( [0, 1, 2, 3, 4, 5], static fn ($x) => new Collection\Vector([$x, $x]) ); diff --git a/tests/unit/Arr/SelectKeysTest.php b/tests/unit/Dict/SelectKeysTest.php similarity index 90% rename from tests/unit/Arr/SelectKeysTest.php rename to tests/unit/Dict/SelectKeysTest.php index cc41dd19..525646ca 100644 --- a/tests/unit/Arr/SelectKeysTest.php +++ b/tests/unit/Dict/SelectKeysTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Psl\Tests\Unit\Arr; +namespace Psl\Tests\Unit\Dict; use PHPUnit\Framework\TestCase; -use Psl\Arr; +use Psl\Dict; final class SelectKeysTest extends TestCase { @@ -14,7 +14,7 @@ final class SelectKeysTest extends TestCase */ public function testSelectKeys(array $result, array $array, array $keys): void { - static::assertSame($result, Arr\select_keys($array, $keys)); + static::assertSame($result, Dict\select_keys($array, $keys)); } public function provideData(): array diff --git a/tests/unit/Arr/SortByKeyTest.php b/tests/unit/Dict/SortByKeyTest.php similarity index 87% rename from tests/unit/Arr/SortByKeyTest.php rename to tests/unit/Dict/SortByKeyTest.php index 5d896ea7..d11bba5a 100644 --- a/tests/unit/Arr/SortByKeyTest.php +++ b/tests/unit/Dict/SortByKeyTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Psl\Tests\Unit\Arr; +namespace Psl\Tests\Unit\Dict; use PHPUnit\Framework\TestCase; -use Psl\Arr; +use Psl\Dict; use Psl\Str; final class SortByKeyTest extends TestCase @@ -15,7 +15,7 @@ final class SortByKeyTest extends TestCase */ public function testSortByKey(array $expected, array $array, ?callable $comparator = null): void { - static::assertSame($expected, Arr\sort_by_key($array, $comparator)); + static::assertSame($expected, Dict\sort_by_key($array, $comparator)); } public function provideData(): array diff --git a/tests/unit/Arr/SortByTest.php b/tests/unit/Dict/SortByTest.php similarity index 76% rename from tests/unit/Arr/SortByTest.php rename to tests/unit/Dict/SortByTest.php index 75d59d63..2a723fa7 100644 --- a/tests/unit/Arr/SortByTest.php +++ b/tests/unit/Dict/SortByTest.php @@ -2,10 +2,11 @@ declare(strict_types=1); -namespace Psl\Tests\Unit\Arr; +namespace Psl\Tests\Unit\Dict; use PHPUnit\Framework\TestCase; -use Psl\Arr; +use Psl\Dict; +use Psl\Iter; use Psl\Str; final class SortByTest extends TestCase @@ -15,7 +16,7 @@ final class SortByTest extends TestCase */ public function testSortBy(array $expected, array $array, callable $scalar_fun, ?callable $comp = null): void { - static::assertSame($expected, Arr\sort_by($array, $scalar_fun, $comp)); + static::assertSame($expected, Dict\sort_by($array, $scalar_fun, $comp)); } public function provideData(): array @@ -23,17 +24,18 @@ public function provideData(): array $a = [1, 2]; $b = [1, 2, 3, 4]; $c = ['a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'qux', 'e' => 'lax']; - $expected = [$a, $b, $c]; + + $expected = [2 => $a, 0 => $b, 1 => $c]; $array = [$b, $c, $a]; $scalar_fun = /** - * @param array $arr + * @param array $array * * @return int * - * @psalm-pure + * @pure */ - static fn ($arr) => Arr\count($arr); + static fn (array $array): int => Iter\count($array); return [ [ @@ -43,14 +45,14 @@ public function provideData(): array ], [ - ['a', 'b', 'c', 'd'], + [1 => 'a', 2 => 'b', 3 => 'c', 0 => 'd'], ['d', 'a', 'b', 'c'], /** * @param string $v * * @return string * - * @psalm-pure + * @pure */ static fn ($v) => $v, ], @@ -63,55 +65,56 @@ public function provideData(): array * * @return string * - * @psalm-pure + * @pure */ static fn ($v) => $v, ], [ - ['d', 'c', 'b', 'a'], + [0 => 'd', 3 => 'c', 2 => 'b', 1 => 'a'], ['d', 'a', 'b', 'c'], /** * @param string $v * * @return string * - * @psalm-pure + * @pure */ static fn ($v) => $v, + /** * @param string $a * @param string $b * * @return int * - * @psalm-pure + * @pure */ static fn (string $a, string $b) => Str\ord($a) > Str\ord($b) ? -1 : 1, ], [ - ['bar', 'qux'], + ['foo' => 'bar', 'baz' => 'qux'], ['foo' => 'bar', 'baz' => 'qux'], /** * @param string $v * * @return string * - * @psalm-pure + * @pure */ static fn ($v) => $v, ], [ - ['jumped', 'the', 'quick', 'brown', 'fox'], + [4 => 'jumped', 0 => 'the', 1 => 'quick', 2 => 'brown', 3 => 'fox'], ['the', 'quick', 'brown', 'fox', 'jumped'], /** * @param string $v * * @return string * - * @psalm-pure + * @pure */ static fn ($v) => Str\Byte\reverse($v), ], diff --git a/tests/unit/Arr/SortTest.php b/tests/unit/Dict/SortTest.php similarity index 77% rename from tests/unit/Arr/SortTest.php rename to tests/unit/Dict/SortTest.php index b0314c2b..9a8d8fe7 100644 --- a/tests/unit/Arr/SortTest.php +++ b/tests/unit/Dict/SortTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Psl\Tests\Unit\Arr; +namespace Psl\Tests\Unit\Dict; use PHPUnit\Framework\TestCase; -use Psl\Arr; +use Psl\Dict; final class SortTest extends TestCase { @@ -14,14 +14,14 @@ final class SortTest extends TestCase */ public function testSort(array $expected, array $array, ?callable $comparator = null): void { - static::assertSame($expected, Arr\sort($array, $comparator)); + static::assertSame($expected, Dict\sort($array, $comparator)); } public function provideData(): array { return [ [ - ['a', 'b', 'c'], + [1 => 'a', 2 => 'b', 0 => 'c'], ['c', 'a', 'b'], ], @@ -34,13 +34,13 @@ public function provideData(): array * * @return int * - * @psalm-pure + * @pure */ static fn (int $a, int $b) => $a <=> $b ? -1 : 1, ], [ - ['bar', 'baz'], + ['foo' => 'bar', 'bar' => 'baz'], ['foo' => 'bar', 'bar' => 'baz'], ], ]; diff --git a/tests/unit/Iter/ChainTest.php b/tests/unit/Iter/ChainTest.php deleted file mode 100644 index fa6d4c28..00000000 --- a/tests/unit/Iter/ChainTest.php +++ /dev/null @@ -1,28 +0,0 @@ - $chain */ - $chain = Iter\chain( - [1], - Iter\range(2, 5), - new Collection\Vector([6]) - ); - - static::assertSame([1, 2, 3, 4, 5, 6], Iter\to_array($chain)); - } -} diff --git a/tests/unit/Iter/ChunkTest.php b/tests/unit/Iter/ChunkTest.php deleted file mode 100644 index e2d3a231..00000000 --- a/tests/unit/Iter/ChunkTest.php +++ /dev/null @@ -1,35 +0,0 @@ -> $expected - * @param iterable $iterable - * - * @dataProvider provideData - */ - public function testChunk(array $expected, iterable $iterable, int $size): void - { - $chunks = Iter\chunk($iterable, $size); - - static::assertSame($expected, Iter\to_array($chunks)); - } - - public function provideData(): iterable - { - yield [[[1], [2], [3]], Iter\range(1, 3), 1]; - yield [[], [], 4]; - yield [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], Iter\range(1, 9), 3]; - yield [[[1, 3, 5], [7, 9]], Iter\range(1, 9, 2), 3]; - yield [[[1, 3], [5, 7], [9]], Iter\range(1, 9, 2), 2]; - } -} diff --git a/tests/unit/Iter/ChunkWithKeysTest.php b/tests/unit/Iter/ChunkWithKeysTest.php deleted file mode 100644 index 28e0c15d..00000000 --- a/tests/unit/Iter/ChunkWithKeysTest.php +++ /dev/null @@ -1,36 +0,0 @@ -> $expected - * @param iterable $iterable - * - * @dataProvider provideData - */ - public function testChunkWithKeys(array $expected, iterable $iterable, int $size): void - { - $chunks = Iter\chunk_with_keys($iterable, $size); - - static::assertSame($expected, Iter\to_array($chunks)); - } - - public function provideData(): iterable - { - yield [[[0 => 1], [1 => 2], [2 => 3]], Iter\range(1, 3), 1]; - yield [[], [], 4]; - yield [[[0 => 1, 1 => 2, 2 => 3], [3 => 4, 4 => 5, 5 => 6], [6 => 7, 7 => 8, 8 => 9]], Iter\range(1, 9), 3]; - yield [[[0 => 1, 1 => 3, 2 => 5], [3 => 7, 4 => 9]], Iter\range(1, 9, 2), 3]; - yield [[[0 => 1, 1 => 3], [2 => 5, 3 => 7], [4 => 9]], Iter\range(1, 9, 2), 2]; - } -} diff --git a/tests/unit/Iter/CountTest.php b/tests/unit/Iter/CountTest.php index 0897001d..1e2f8976 100644 --- a/tests/unit/Iter/CountTest.php +++ b/tests/unit/Iter/CountTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use Psl\Collection; use Psl\Iter; +use Psl\Vec; final class CountTest extends TestCase { @@ -23,8 +24,8 @@ public function provideData(): iterable yield [0, []]; yield [1, [null]]; yield [3, [1, 2, 3]]; - yield [10, Iter\range(1, 10)]; + yield [10, Vec\range(1, 10)]; yield [1, (static fn () => yield 1 => 2)()]; - yield [21, new Collection\Vector(Iter\range(0, 100, 5))]; + yield [21, Collection\Vector::fromArray(Vec\range(0, 100, 5))]; } } diff --git a/tests/unit/Iter/DiffByKeyTest.php b/tests/unit/Iter/DiffByKeyTest.php deleted file mode 100644 index 45ef5b3f..00000000 --- a/tests/unit/Iter/DiffByKeyTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 7, 7 => 8], Iter\range(1, 8), Iter\range(1, 6), []]; - yield [[7 => 8], Iter\range(1, 8), Iter\range(1, 6), [6 => 7]]; - } -} diff --git a/tests/unit/Iter/DropTest.php b/tests/unit/Iter/DropTest.php deleted file mode 100644 index 5d4138e1..00000000 --- a/tests/unit/Iter/DropTest.php +++ /dev/null @@ -1,39 +0,0 @@ - 4, 4 => 5], [1, 2, 3, 4, 5], 3]; - yield [[2 => 3, 3 => 4, 4 => 5], [1, 2, 3, 4, 5], 2]; - yield [[], [1, 2, 3, 4, 5], 5]; - - yield [[1, 2, 3, 4, 5], Iter\range(1, 5), 0]; - yield [[3 => 4, 4 => 5], Iter\range(1, 5), 3]; - yield [[2 => 3, 3 => 4, 4 => 5], Iter\range(1, 5), 2]; - yield [[], Iter\range(1, 5), 5]; - - yield [[1, 2, 3, 4, 5], Iter\range(1, 5), 0]; - yield [[3 => 4, 4 => 5], Iter\range(1, 5), 3]; - yield [[2 => 3, 3 => 4, 4 => 5], Iter\range(1, 5), 2]; - yield [[], Iter\range(1, 5), 5]; - } -} diff --git a/tests/unit/Iter/DropWhileTest.php b/tests/unit/Iter/DropWhileTest.php deleted file mode 100644 index 620787b2..00000000 --- a/tests/unit/Iter/DropWhileTest.php +++ /dev/null @@ -1,39 +0,0 @@ - false]; - yield [[3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 3]; - yield [[2 => 3, 3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 2]; - yield [[], [1, 2, 3, 4, 5], static fn (int $_) => true]; - - yield [[1, 2, 3, 4, 5], Iter\range(1, 5), static fn (int $_): bool => false]; - yield [[3 => 4, 4 => 5], Iter\range(1, 5), static fn (int $i) => $i <= 3]; - yield [[2 => 3, 3 => 4, 4 => 5], Iter\range(1, 5), static fn (int $i) => $i <= 2]; - yield [[], Iter\range(1, 5), static fn (int $_) => true]; - - yield [[1, 2, 3, 4, 5], Iter\range(1, 5), static fn (int $_): bool => false]; - yield [[3 => 4, 4 => 5], Iter\range(1, 5), static fn (int $i) => $i <= 3]; - yield [[2 => 3, 3 => 4, 4 => 5], Iter\range(1, 5), static fn (int $i) => $i <= 2]; - yield [[], Iter\range(1, 5), static fn (int $_) => true]; - } -} diff --git a/tests/unit/Iter/EnumerateTest.php b/tests/unit/Iter/EnumerateTest.php deleted file mode 100644 index 65c6ad69..00000000 --- a/tests/unit/Iter/EnumerateTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'b', 'c' => 'd']]; - yield [[['a', 'b'], ['a', 'b'], ['a', 'b']], (static function () { - yield 'a' => 'b'; - yield 'a' => 'b'; - yield 'a' => 'b'; - })()]; - yield [[['a', null], ['b', 0]], ['a' => null, 'b' => 0]]; - } -} diff --git a/tests/unit/Iter/FilterKeysTest.php b/tests/unit/Iter/FilterKeysTest.php deleted file mode 100644 index 4ceea854..00000000 --- a/tests/unit/Iter/FilterKeysTest.php +++ /dev/null @@ -1,52 +0,0 @@ - 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn () => false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $k): bool => 1 !== $k]; - - yield [[1 => 'b'], Iter\Iterator::create(['a', 'b'])]; - yield [[], Iter\Iterator::create(['a', 'b']), static fn () => false]; - yield [['a', 'b'], Iter\Iterator::create(['a', 'b']), static fn (int $_): bool => true]; - yield [['a'], Iter\Iterator::create(['a', 'b']), static fn (int $k): bool => 1 !== $k]; - - yield [[1 => 'b'], (static function () { - yield 'a'; - yield 'b'; - })()]; - yield [[], (static function () { - yield 'a'; - yield 'b'; - })(), static fn () => false]; - yield [['a', 'b'], (static function () { - yield 'a'; - yield 'b'; - })(), static fn (int $_): bool => true]; - yield [['a'], (static function () { - yield 'a'; - yield 'b'; - })(), static fn (int $k): bool => 1 !== $k]; - } -} diff --git a/tests/unit/Iter/FilterNullsTest.php b/tests/unit/Iter/FilterNullsTest.php deleted file mode 100644 index cda6ab65..00000000 --- a/tests/unit/Iter/FilterNullsTest.php +++ /dev/null @@ -1,34 +0,0 @@ - false]; - yield [['a', 'b'], ['a', 'b'], static fn (string $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (string $v): bool => 'b' !== $v]; - - yield [['a', 'b'], Iter\Iterator::create(['a', 'b'])]; - yield [[], Iter\Iterator::create(['a', 'b']), static fn () => false]; - yield [['a', 'b'], Iter\Iterator::create(['a', 'b']), static fn (string $_): bool => true]; - yield [['a'], Iter\Iterator::create(['a', 'b']), static fn (string $v): bool => 'b' !== $v]; - - yield [['a', 'b'], (static function () { - yield 'a'; - yield 'b'; - })()]; - yield [[], (static function () { - yield 'a'; - yield 'b'; - })(), static fn () => false]; - yield [['a', 'b'], (static function () { - yield 'a'; - yield 'b'; - })(), static fn (string $_): bool => true]; - yield [['a'], (static function () { - yield 'a'; - yield 'b'; - })(), static fn (string $v): bool => 'b' !== $v]; - } -} diff --git a/tests/unit/Iter/FilterWithKeyTest.php b/tests/unit/Iter/FilterWithKeyTest.php deleted file mode 100644 index ab3b7577..00000000 --- a/tests/unit/Iter/FilterWithKeyTest.php +++ /dev/null @@ -1,62 +0,0 @@ - false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_k, string $_v): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 0 !== $k]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 1 !== $k]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 1 !== $k]; - yield [[1 => 'b'], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 0 !== $k]; - - yield [[], new SplFixedArray(0)]; - yield [['a', 'b'], new Collection\Vector(['a', 'b'])]; - yield [[], new Collection\Map(['a', 'b']), static fn (int $_k, string $_v) => false]; - yield [['a', 'b'], Iter\Iterator::create(['a', 'b']), static fn (int $_k, string $_v): bool => true]; - yield [['a'], new Collection\MutableMap(['a', 'b']), static fn (int $k, string $v): bool => 'b' !== $v]; - yield [ - [], - new Collection\MutableVector(['a', 'b']), - static fn (int $k, string $v): bool => 'b' !== $v && 0 !== $k - ]; - yield [ - ['a'], - Iter\Iterator::create(['a', 'b']), - static fn (int $k, string $v): bool => 'b' !== $v && 1 !== $k - ]; - yield [[], new ArrayIterator(['a', 'b']), static fn (int $k, string $v): bool => 'a' !== $v && 1 !== $k]; - yield [[1 => 'b'], new ArrayObject(['a', 'b']), static fn (int $k, string $v): bool => 'a' !== $v && 0 !== $k]; - - $doublyLinkedList = new SplDoublyLinkedList(); - $doublyLinkedList->add(0, 'a'); - $doublyLinkedList->add(1, 'b'); - yield [['a', 'b'], $doublyLinkedList]; - } -} diff --git a/tests/unit/Iter/FlatMapTest.php b/tests/unit/Iter/FlatMapTest.php deleted file mode 100644 index 9ddc548e..00000000 --- a/tests/unit/Iter/FlatMapTest.php +++ /dev/null @@ -1,36 +0,0 @@ - [$v]]; - yield [[1, 2, 2, 4, 3, 6], [1, 2, 3], static fn (int $v): array => [$v, $v * 2]]; - yield [[], [1, 2], static fn (int $k): array => []]; - yield [[[1], [2]], [1, 2], static fn (int $v): array => [[$v]]]; - yield [[], [], static fn (int $k): array => []]; - yield [ - ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog', ''], - ['The quick brown', 'fox', 'jumps over', 'the lazy dog', ''], - static fn (string $v): array => Str\Split($v, ' ') - ]; - } -} diff --git a/tests/unit/Iter/FlattenTest.php b/tests/unit/Iter/FlattenTest.php deleted file mode 100644 index 6fbb2ab5..00000000 --- a/tests/unit/Iter/FlattenTest.php +++ /dev/null @@ -1,45 +0,0 @@ - 'b', 'c' => 'd', 'e' => 'f']), - (static fn () => yield 'hey' => 'hello')() - ]); - - static::assertSame([ - 0 => 1, - 1 => 2, - 2 => 3, - 'a' => 'b', - 'c' => 'd', - 'e' => 'f', - 'hey' => 'hello' - ], Iter\to_array_with_keys($result)); - } - - public function testFlattenSameKeys(): void - { - $result = Iter\flatten(new Collection\Vector([ - new Collection\MutableMap(['a' => 'b']), - ['a' => 'foo'] - ])); - - static::assertSame('a', Iter\first_key($result)); - static::assertSame('b', Iter\first($result)); - - static::assertSame('a', Iter\last_key($result)); - static::assertSame('foo', Iter\last($result)); - } -} diff --git a/tests/unit/Iter/FlipTest.php b/tests/unit/Iter/FlipTest.php deleted file mode 100644 index 16f267cf..00000000 --- a/tests/unit/Iter/FlipTest.php +++ /dev/null @@ -1,32 +0,0 @@ - $a, 'b' => $b]); - - static::assertSame('a', Iter\first_key($iterable)); - static::assertSame($a, Iter\first($iterable)); - static::assertSame('b', Iter\last_key($iterable)); - static::assertSame($b, Iter\last($iterable)); - - $result = Iter\flip($iterable); - - static::assertSame($a, Iter\first_key($result)); - static::assertSame('a', Iter\first($result)); - static::assertSame($b, Iter\last_key($result)); - static::assertSame('b', Iter\last($result)); - } -} diff --git a/tests/unit/Iter/FromEntriesTest.php b/tests/unit/Iter/FromEntriesTest.php deleted file mode 100644 index 59f59f97..00000000 --- a/tests/unit/Iter/FromEntriesTest.php +++ /dev/null @@ -1,45 +0,0 @@ - false); - - static::assertSame('hello', Iter\first_key($actual)); - static::assertSame('world', Iter\last_key($actual)); - static::assertFalse(Iter\first($actual)); - static::assertFalse(Iter\last($actual)); - } - - public function testFromKeysWithNonArrayKeyKeys(): void - { - $actual = Iter\from_keys([ - [1, 'hello'], - [2, 'world'] - ], static fn (array $k) => $k[1]); - - static::assertSame([1, 'hello'], Iter\first_key($actual)); - static::assertSame([2, 'world'], Iter\last_key($actual)); - static::assertSame('hello', Iter\first($actual)); - static::assertSame('world', Iter\last($actual)); - } -} diff --git a/tests/unit/Iter/IsEmptyTest.php b/tests/unit/Iter/IsEmptyTest.php index 20a7d62a..88c12283 100644 --- a/tests/unit/Iter/IsEmptyTest.php +++ b/tests/unit/Iter/IsEmptyTest.php @@ -20,7 +20,7 @@ public function testIsEmpty(bool $expected, iterable $iterable): void public function provideData(): iterable { yield [true, []]; - yield [true, Iter\from_entries([])]; + yield [true, Iter\to_iterator([])]; yield [true, (static fn () => yield from [])()]; yield [false, [null]]; diff --git a/tests/unit/Iter/IteratorTest.php b/tests/unit/Iter/IteratorTest.php index e823938e..cf33355a 100644 --- a/tests/unit/Iter/IteratorTest.php +++ b/tests/unit/Iter/IteratorTest.php @@ -25,6 +25,19 @@ public function testCreateFromFactory(): void static::assertCount(3, $iterator); } + public function testKeyIteration(): void + { + $iterator = Iter\Iterator::from((static fn () => yield from [1, 2, 3])); + $keys = []; + while ($iterator->valid()) { + $keys[] = $iterator->key(); + + $iterator->next(); + } + + static::assertSame([0, 1, 2], $keys); + } + public function testSeek(): void { $iterator = new Iter\Iterator((static fn () => yield from [1, 2, 3, 4, 5])()); diff --git a/tests/unit/Iter/KeysTest.php b/tests/unit/Iter/KeysTest.php deleted file mode 100644 index ea5b5eb9..00000000 --- a/tests/unit/Iter/KeysTest.php +++ /dev/null @@ -1,32 +0,0 @@ - $k]; - yield [[1, 2 => 2, 4 => 3], [1, 2, 3], static fn (int $k): int => $k * 2]; - yield [['0' => 1, '1' => 2, '2' => 3], [1, 2, 3], static fn (int $k): string => (string) $k]; - yield [[], [], static fn (int $k): string => (string) $k]; - yield [[], Iter\Iterator::create([]), static fn (int $k): string => (string) $k]; - yield [['0' => 1, '1' => 2], Iter\Iterator::create([1, 2]), static fn (int $k): string => (string) $k]; - } -} diff --git a/tests/unit/Iter/MapTest.php b/tests/unit/Iter/MapTest.php deleted file mode 100644 index 4dcef2f7..00000000 --- a/tests/unit/Iter/MapTest.php +++ /dev/null @@ -1,31 +0,0 @@ - $v]; - yield [[2, 4, 6], [1, 2, 3], static fn (int $v): int => $v * 2]; - yield [['1', '2', '3'], [1, 2, 3], static fn (int $v): string => (string) $v]; - yield [[], [], static fn (int $k): string => (string) $v]; - yield [[], Iter\Iterator::create([]), static fn (int $v): string => (string) $v]; - yield [['1', '2'], Iter\Iterator::create([1, 2]), static fn (int $v): string => (string) $v]; - } -} diff --git a/tests/unit/Iter/MapWithKeyTest.php b/tests/unit/Iter/MapWithKeyTest.php deleted file mode 100644 index 07c7f318..00000000 --- a/tests/unit/Iter/MapWithKeyTest.php +++ /dev/null @@ -1,31 +0,0 @@ - $k + $v]; - yield [[0, 4, 16], [1, 2, 3], static fn (int $k, int $v): int => $k * (2 ** $v)]; - yield [['1', '3', '5'], [1, 2, 3], static fn (int $k, int $v): string => (string) ($k + $v)]; - yield [[], [], static fn (int $k, int $v): string => (string) ($k + $v)]; - yield [[], Iter\Iterator::create([]), static fn (int $k, int $v): string => (string) ($k + $v)]; - yield [['1', '3'], Iter\Iterator::create([1, 2]), static fn (int $k, int $v): string => (string) ($k + $v)]; - } -} diff --git a/tests/unit/Iter/MergeTest.php b/tests/unit/Iter/MergeTest.php deleted file mode 100644 index adc44fac..00000000 --- a/tests/unit/Iter/MergeTest.php +++ /dev/null @@ -1,23 +0,0 @@ - Str\chr($i + 65), - static fn ($i) => 2 ** $i - ); - - static::assertSame([ - 1 => 'A', 2 => 'B', 4 => 'C', 8 => 'D', 16 => 'E', 32 => 'F', - 64 => 'G', 128 => 'H', 256 => 'I', 512 => 'J', 1024 => 'K' - ], Iter\to_array_with_keys($result)); - } -} diff --git a/tests/unit/Iter/PullWithKeyTest.php b/tests/unit/Iter/PullWithKeyTest.php deleted file mode 100644 index 95a5f137..00000000 --- a/tests/unit/Iter/PullWithKeyTest.php +++ /dev/null @@ -1,26 +0,0 @@ - Str\chr($v + $k + 65), - static fn ($k, $v) => 2 ** ($v + $k) - ); - - static::assertSame([ - 1 => 'A', 4 => 'C', 16 => 'E', 64 => 'G', 256 => 'I', 1024 => 'K', - 4096 => 'M', 16384 => 'O', 65536 => 'Q', 262144 => 'S', 1048576 => 'U' - ], Iter\to_array_with_keys($result)); - } -} diff --git a/tests/unit/Iter/RandomTest.php b/tests/unit/Iter/RandomTest.php index b190bf0b..b8f19ace 100644 --- a/tests/unit/Iter/RandomTest.php +++ b/tests/unit/Iter/RandomTest.php @@ -21,6 +21,10 @@ public function testRandom(): void $value = Iter\random($iterable); static::assertTrue(Iter\contains($iterable, $value)); + + $value = Iter\random([1]); + + static::assertSame(1, $value); } public function testRandomWithEmptyIterator(): void diff --git a/tests/unit/Iter/RangeTest.php b/tests/unit/Iter/RangeTest.php deleted file mode 100644 index 0851e91c..00000000 --- a/tests/unit/Iter/RangeTest.php +++ /dev/null @@ -1,37 +0,0 @@ -expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('If start < end, the step must be positive.'); - - Iter\range(0, 10, -2); - } - - public function testRandomThrowsIfStartIsGreaterThanEndAndStepIsPositive(): void - { - $this->expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('If start > end, the step must be negative.'); - - Iter\range(20, 10, 2); - } -} diff --git a/tests/unit/Iter/ReductionsTest.php b/tests/unit/Iter/ReductionsTest.php deleted file mode 100644 index 565854b6..00000000 --- a/tests/unit/Iter/ReductionsTest.php +++ /dev/null @@ -1,28 +0,0 @@ - $accumulator, null]; - yield [[1, 3, 6], [1, 2, 3], static fn ($accumulator, $k, $v) => $accumulator + $v, 0]; - yield [[1, 3, 6], Iter\to_iterator([1, 2, 3]), static fn ($accumulator, $k, $v) => $accumulator + $v, 0]; - } -} diff --git a/tests/unit/Iter/ReindexTest.php b/tests/unit/Iter/ReindexTest.php deleted file mode 100644 index e79b90b1..00000000 --- a/tests/unit/Iter/ReindexTest.php +++ /dev/null @@ -1,18 +0,0 @@ - $value); - - static::assertSame([1 => 1, 2 => 2, 3 => 3], Iter\to_array_with_keys($result)); - } -} diff --git a/tests/unit/Iter/RepeatTest.php b/tests/unit/Iter/RepeatTest.php deleted file mode 100644 index 7a3fd1c1..00000000 --- a/tests/unit/Iter/RepeatTest.php +++ /dev/null @@ -1,38 +0,0 @@ -expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Number of repetitions must be non-negative.'); - - Iter\repeat(4, -1); - } - - public function testRepeatToInfinityIfNumIsNotProvided(): void - { - $result = Iter\repeat('hello'); - $result->seek((int) Math\INFINITY); - - static::assertTrue($result->valid()); - static::assertSame('hello', $result->current()); - static::assertSame((int) Math\INFINITY, $result->key()); - } -} diff --git a/tests/unit/Iter/ReproduceTest.php b/tests/unit/Iter/ReproduceTest.php deleted file mode 100644 index eda60a17..00000000 --- a/tests/unit/Iter/ReproduceTest.php +++ /dev/null @@ -1,38 +0,0 @@ -expectException(InvariantViolationException::class); - $this->expectExceptionMessage('The number of times you want to reproduce must be at least 1.'); - - Iter\reproduce(Fun\identity(), 0); - } - - public function testReproduceToInfinityIfNumIsNotProvided(): void - { - $result = Iter\reproduce(static fn () => 'hello'); - $result->seek((int) Math\INFINITY); - - static::assertTrue($result->valid()); - static::assertSame('hello', $result->current()); - static::assertSame((int) Math\INFINITY, $result->key()); - } -} diff --git a/tests/unit/Iter/ReverseTest.php b/tests/unit/Iter/ReverseTest.php deleted file mode 100644 index 11871d46..00000000 --- a/tests/unit/Iter/ReverseTest.php +++ /dev/null @@ -1,25 +0,0 @@ -expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Start offset must be non-negative.'); - - Iter\slice([1, 2, 3], -3); - } - - public function testSliceThrowsIfLengthIsNegative(): void - { - $this->expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Length must be non-negative.'); - - Iter\slice([1, 2, 3], 1, -3); - } -} diff --git a/tests/unit/Iter/TakeTest.php b/tests/unit/Iter/TakeTest.php deleted file mode 100644 index be27369d..00000000 --- a/tests/unit/Iter/TakeTest.php +++ /dev/null @@ -1,27 +0,0 @@ -expectException(Psl\Exception\InvariantViolationException::class); - $this->expectExceptionMessage('Length must be non-negative.'); - - Iter\take([1, 2, 3], -3); - } -} diff --git a/tests/unit/Iter/TakeWhileTest.php b/tests/unit/Iter/TakeWhileTest.php deleted file mode 100644 index 7b1ed5c2..00000000 --- a/tests/unit/Iter/TakeWhileTest.php +++ /dev/null @@ -1,39 +0,0 @@ - false]; - yield [[1, 2, 3], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 3]; - yield [[1, 2], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 2]; - yield [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], static fn (int $_) => true]; - - yield [[], Iter\range(1, 5), static fn (int $_): bool => false]; - yield [[1, 2, 3], Iter\range(1, 5), static fn (int $i) => $i <= 3]; - yield [[1, 2], Iter\range(1, 5), static fn (int $i) => $i <= 2]; - yield [[1, 2, 3, 4, 5], Iter\range(1, 5), static fn (int $_) => true]; - - yield [[], Iter\range(1, 5), static fn (int $_): bool => false]; - yield [[1, 2 , 3], Iter\range(1, 5), static fn (int $i) => $i <= 3]; - yield [[1, 2], Iter\range(1, 5), static fn (int $i) => $i <= 2]; - yield [[1, 2, 3, 4, 5], Iter\range(1, 5), static fn (int $_) => true]; - } -} diff --git a/tests/unit/Iter/ToArrayTest.php b/tests/unit/Iter/ToArrayTest.php deleted file mode 100644 index 5d1e40f7..00000000 --- a/tests/unit/Iter/ToArrayTest.php +++ /dev/null @@ -1,50 +0,0 @@ - 'bar', 'baz' => 'qux'], ['bar', 'qux']]; - yield [[], []]; - yield [['hello', 'world'], ['hello', 'world']]; - - yield [new Collection\Vector([1, 2, 3]), [1, 2, 3]]; - yield [new Collection\Vector([null]), [null]]; - yield [new Collection\Map(['foo' => 'bar', 'baz' => 'qux']), ['bar', 'qux']]; - yield [new Collection\Map([]), []]; - yield [new Collection\MutableVector(['hello', 'world']), ['hello', 'world']]; - - yield [$this->createGeneratorFromIterable([1, 2, 3]), [1, 2, 3]]; - yield [$this->createGeneratorFromIterable([null]), [null]]; - yield [$this->createGeneratorFromIterable(['foo' => 'bar', 'baz' => 'qux']), ['bar', 'qux']]; - yield [$this->createGeneratorFromIterable([]), []]; - yield [$this->createGeneratorFromIterable(['hello', 'world']), ['hello', 'world']]; - } - - private function createGeneratorFromIterable(iterable $iterable): iterable - { - foreach ($iterable as $k => $v) { - yield $k => $v; - } - } -} diff --git a/tests/unit/Iter/ToArrayWithKeysTest.php b/tests/unit/Iter/ToArrayWithKeysTest.php deleted file mode 100644 index 46143715..00000000 --- a/tests/unit/Iter/ToArrayWithKeysTest.php +++ /dev/null @@ -1,50 +0,0 @@ - 'bar', 'baz' => 'qux'], ['foo' => 'bar', 'baz' => 'qux']]; - yield [[], []]; - yield [['hello', 'world'], ['hello', 'world']]; - - yield [new Collection\Vector([1, 2, 3]), [1, 2, 3]]; - yield [new Collection\Vector([null]), [null]]; - yield [new Collection\Map(['foo' => 'bar', 'baz' => 'qux']), ['foo' => 'bar', 'baz' => 'qux']]; - yield [new Collection\Map([]), []]; - yield [new Collection\MutableVector(['hello', 'world']), ['hello', 'world']]; - - yield [$this->createGeneratorFromIterable([1, 2, 3]), [1, 2, 3]]; - yield [$this->createGeneratorFromIterable([null]), [null]]; - yield [$this->createGeneratorFromIterable(['foo' => 'bar', 'baz' => 'qux']), ['foo' => 'bar', 'baz' => 'qux']]; - yield [$this->createGeneratorFromIterable([]), []]; - yield [$this->createGeneratorFromIterable(['hello', 'world']), ['hello', 'world']]; - } - - private function createGeneratorFromIterable(iterable $iterable): iterable - { - foreach ($iterable as $k => $v) { - yield $k => $v; - } - } -} diff --git a/tests/unit/Iter/ToIteratorTest.php b/tests/unit/Iter/ToIteratorTest.php index dbada8a0..1ec3856a 100644 --- a/tests/unit/Iter/ToIteratorTest.php +++ b/tests/unit/Iter/ToIteratorTest.php @@ -5,11 +5,14 @@ namespace Psl\Tests\Unit\Iter; use PHPUnit\Framework\TestCase; +use Psl\Dict; use Psl\Iter; final class ToIteratorTest extends TestCase { /** + * @param array $array + * * @dataProvider provideToIteratorData */ public function testToIterator(array $array): void @@ -17,9 +20,12 @@ public function testToIterator(array $array): void $iterator = Iter\to_iterator($array); static::assertCount(Iter\count($array), $iterator); - static::assertSame($array, Iter\to_array_with_keys($iterator)); + static::assertSame($array, Dict\from_iterable($iterator)); } + /** + * @return iterable}> + */ public function provideToIteratorData(): iterable { yield [[1, 2, 3]]; diff --git a/tests/unit/Iter/ValuesTest.php b/tests/unit/Iter/ValuesTest.php deleted file mode 100644 index a1e5ed34..00000000 --- a/tests/unit/Iter/ValuesTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'hello', 'bar' => 'world'])]; - yield [['foo', 'bar'], new Collection\Vector(['foo', 'bar'])]; - } -} diff --git a/tests/unit/Iter/ZipTest.php b/tests/unit/Iter/ZipTest.php deleted file mode 100644 index 9fbc1527..00000000 --- a/tests/unit/Iter/ZipTest.php +++ /dev/null @@ -1,48 +0,0 @@ -key(); - $v = $result->current(); - static::assertSame([0, 0, 0], $k); - static::assertSame([1, 5, 10], $v); - - $result->next(); - - $k = $result->key(); - $v = $result->current(); - static::assertSame([1, 1, 1], $k); - static::assertSame([2, 6, 11], $v); - - $result->next(); - - $k = $result->key(); - $v = $result->current(); - static::assertSame([2, 2, 2], $k); - static::assertSame([3, 7, 12], $v); - } - - public function testZipWithZeroIterables(): void - { - $result = Iter\zip(...[]); - - static::assertCount(0, $result); - } -} diff --git a/tests/unit/Math/MaxByTest.php b/tests/unit/Math/MaxByTest.php index a81bef31..0b93a1bc 100644 --- a/tests/unit/Math/MaxByTest.php +++ b/tests/unit/Math/MaxByTest.php @@ -6,7 +6,7 @@ use Generator; use PHPUnit\Framework\TestCase; -use Psl\Arr; +use Psl\Iter; use Psl\Math; use Psl\Str; @@ -35,7 +35,7 @@ public function provideData(): Generator ['foo', 'bar'], ['foo', 'bar', 'baz'] ], - static fn ($arr) => Arr\count($arr), + static fn ($arr) => Iter\count($arr), ]; yield [ diff --git a/tests/unit/Math/MaxvaTest.php b/tests/unit/Math/MaxvaTest.php index b1ef9a1e..98ebe18b 100644 --- a/tests/unit/Math/MaxvaTest.php +++ b/tests/unit/Math/MaxvaTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Iter; use Psl\Math; +use Psl\Vec; final class MaxvaTest extends TestCase { @@ -25,14 +25,14 @@ public function provideData(): array 10, 10, 5, - ...Iter\range(0, 9, 2) + ...Vec\range(0, 9, 2) ], [ 18, 18, 15, - ...Iter\to_array(Iter\range(0, 10)), + ...Vec\range(0, 10), 15 ], @@ -40,7 +40,7 @@ public function provideData(): array 64, 19, 15, - ...Iter\range(0, 45, 5), + ...Vec\range(0, 45, 5), 52, 64 ] diff --git a/tests/unit/Math/MeanTest.php b/tests/unit/Math/MeanTest.php index 01649965..fcc51b8e 100644 --- a/tests/unit/Math/MeanTest.php +++ b/tests/unit/Math/MeanTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Arr; use Psl\Math; +use Psl\Vec; final class MeanTest extends TestCase { @@ -76,7 +76,7 @@ public function provideData(): array [ 100.0, - Arr\fill(100, 0, 100) + Vec\fill(100, 100) ], [ diff --git a/tests/unit/Math/MedianTest.php b/tests/unit/Math/MedianTest.php index 286402dc..94f3d3e2 100644 --- a/tests/unit/Math/MedianTest.php +++ b/tests/unit/Math/MedianTest.php @@ -5,9 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Arr; -use Psl\Iter; use Psl\Math; +use Psl\Vec; final class MedianTest extends TestCase { @@ -27,7 +26,7 @@ public function provideData(): array [ 10, 5, - ...Iter\range(0, 9, 2), + ...Vec\range(0, 9, 2), ], ], @@ -36,7 +35,7 @@ public function provideData(): array [ 18, 15, - ...Iter\range(0, 10), + ...Vec\range(0, 10), 15, ], ], @@ -46,7 +45,7 @@ public function provideData(): array [ 19, 15, - ...Iter\range(0, 45, 5), + ...Vec\range(0, 45, 5), 52, 64, ], @@ -54,7 +53,7 @@ public function provideData(): array [ 100.0, - Arr\fill(100, 0, 100) + Vec\fill(100, 100) ], [ diff --git a/tests/unit/Math/MinByTest.php b/tests/unit/Math/MinByTest.php index df216a48..d107a221 100644 --- a/tests/unit/Math/MinByTest.php +++ b/tests/unit/Math/MinByTest.php @@ -9,6 +9,7 @@ use Psl\Iter; use Psl\Math; use Psl\Str; +use Psl\Vec; final class MinByTest extends TestCase { @@ -40,7 +41,7 @@ public function provideData(): Generator yield [ 0, - [...Iter\range(0, 9)], + [...Vec\range(0, 9)], static fn ($i) => $i, ]; diff --git a/tests/unit/Math/MinTest.php b/tests/unit/Math/MinTest.php index 5d559589..b5121817 100644 --- a/tests/unit/Math/MinTest.php +++ b/tests/unit/Math/MinTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Iter; use Psl\Math; +use Psl\Vec; final class MinTest extends TestCase { @@ -24,12 +24,12 @@ public function provideData(): array return [ [ 0, - [...Iter\range(0, 10, 2)] + [...Vec\range(0, 10, 2)] ], [ 4, - [...Iter\range(5, 10), 4] + [...Vec\range(5, 10), 4] ], [ diff --git a/tests/unit/Math/MinvaTest.php b/tests/unit/Math/MinvaTest.php index 68430510..d0253aed 100644 --- a/tests/unit/Math/MinvaTest.php +++ b/tests/unit/Math/MinvaTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Iter; use Psl\Math; +use Psl\Vec; final class MinvaTest extends TestCase { @@ -25,14 +25,14 @@ public function provideData(): array 5, 10, 5, - ...Iter\range(7, 9, 2) + ...Vec\range(7, 9, 2) ], [ 4, 18, 15, - ...Iter\to_array(Iter\range(4, 10)), + ...Vec\range(4, 10), 15 ], @@ -40,7 +40,7 @@ public function provideData(): array 15, 19, 15, - ...Iter\range(40, 45, 5), + ...Vec\range(40, 45, 5), 52, 64 ] diff --git a/tests/unit/Math/SumFloatsTest.php b/tests/unit/Math/SumFloatsTest.php index 07277c11..af90aee7 100644 --- a/tests/unit/Math/SumFloatsTest.php +++ b/tests/unit/Math/SumFloatsTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Iter; use Psl\Math; +use Psl\Vec; final class SumFloatsTest extends TestCase { @@ -26,7 +26,7 @@ public function provideData(): array [ 10.9, 5, - ...Iter\range(0, 9.8798, 0.48), + ...Vec\range(0, 9.8798, 0.48), ], ], @@ -35,7 +35,7 @@ public function provideData(): array [ 18, 15, - ...Iter\to_array(Iter\range(0, 10)), + ...Vec\range(0, 10), 15, ], ], @@ -45,7 +45,7 @@ public function provideData(): array [ 19.5, 15.8, - ...Iter\range(0.5, 45, 5.98), + ...Vec\range(0.5, 45, 5.98), 52.8, 64, ] diff --git a/tests/unit/Math/SumTest.php b/tests/unit/Math/SumTest.php index 63c3c4f9..9062769d 100644 --- a/tests/unit/Math/SumTest.php +++ b/tests/unit/Math/SumTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Math; use PHPUnit\Framework\TestCase; -use Psl\Iter; use Psl\Math; +use Psl\Vec; final class SumTest extends TestCase { @@ -26,7 +26,7 @@ public function provideData(): array [ 10, 5, - ...Iter\range(0, 9), + ...Vec\range(0, 9), ], ], @@ -35,7 +35,7 @@ public function provideData(): array [ 18, 15, - ...Iter\to_array(Iter\range(0, 10)), + ...Vec\range(0, 10), 15, ], ], @@ -45,7 +45,7 @@ public function provideData(): array [ 178, 15, - ...Iter\range(0, 45, 5), + ...Vec\range(0, 45, 5), 52, 64, ] diff --git a/tests/unit/Password/PasswordTest.php b/tests/unit/Password/PasswordTest.php index c01c584f..0d67f13d 100644 --- a/tests/unit/Password/PasswordTest.php +++ b/tests/unit/Password/PasswordTest.php @@ -5,10 +5,10 @@ namespace Psl\Tests\Unit\Password; use PHPUnit\Framework\TestCase; -use Psl\Arr; use Psl\Password; use Psl\SecureRandom; use Psl\Str; +use Psl\Vec; use const PASSWORD_BCRYPT; @@ -23,7 +23,7 @@ public function testAlgorithms(): void static::assertContains(Password\ARGON2I_ALGORITHM, $algorithms); static::assertContains(Password\ARGON2ID_ALGORITHM, $algorithms); - $algos = Arr\map( + $algos = Vec\map( password_algos(), static fn (string $value): string => PASSWORD_BCRYPT === $value ? Password\BCRYPT_ALGORITHM : $value ); diff --git a/tests/unit/RandomSequence/SecureSequenceTest.php b/tests/unit/RandomSequence/SecureSequenceTest.php new file mode 100644 index 00000000..c96ae3fe --- /dev/null +++ b/tests/unit/RandomSequence/SecureSequenceTest.php @@ -0,0 +1,21 @@ +next(); + $b = $sequence->next(); + + static::assertNotSame($a, $b); + } +} diff --git a/tests/unit/Type/Exception/TypeAssertExceptionTest.php b/tests/unit/Type/Exception/TypeAssertExceptionTest.php index 28e1e6c6..6786dec5 100644 --- a/tests/unit/Type/Exception/TypeAssertExceptionTest.php +++ b/tests/unit/Type/Exception/TypeAssertExceptionTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Type\Exception; use PHPUnit\Framework\TestCase; -use Psl\Arr; use Psl\Collection; +use Psl\Iter; use Psl\Str; use Psl\Type; @@ -31,7 +31,7 @@ public function testIncorrectIterableKey(): void $frames = $trace->getFrames(); static::assertCount(1, $frames); - static::assertSame('iterable', Arr\first($frames)); + static::assertSame('iterable', Iter\first($frames)); } } diff --git a/tests/unit/Type/Exception/TypeCoercionExceptionTest.php b/tests/unit/Type/Exception/TypeCoercionExceptionTest.php index 1e858c8a..a7e789e8 100644 --- a/tests/unit/Type/Exception/TypeCoercionExceptionTest.php +++ b/tests/unit/Type/Exception/TypeCoercionExceptionTest.php @@ -5,8 +5,8 @@ namespace Psl\Tests\Unit\Type\Exception; use PHPUnit\Framework\TestCase; -use Psl\Arr; use Psl\Collection; +use Psl\Iter; use Psl\Str; use Psl\Type; @@ -34,7 +34,7 @@ public function testIncorrectIterableKey(): void $frames = $trace->getFrames(); static::assertCount(1, $frames); - static::assertSame('iterable', Arr\first($frames)); + static::assertSame('iterable', Iter\first($frames)); } } diff --git a/tests/unit/Type/IsArrayTest.php b/tests/unit/Type/IsArrayTest.php deleted file mode 100644 index 27d32dcd..00000000 --- a/tests/unit/Type/IsArrayTest.php +++ /dev/null @@ -1,54 +0,0 @@ - yield 5)(), - ], - - [ - false, - 4, - ], - - [ - false, - false, - ], - - [ - false, - STDOUT, - ], - ]; - } -} diff --git a/tests/unit/Type/IsArraykeyTest.php b/tests/unit/Type/IsArraykeyTest.php deleted file mode 100644 index 34b16876..00000000 --- a/tests/unit/Type/IsArraykeyTest.php +++ /dev/null @@ -1,34 +0,0 @@ - 'hello']; - yield [true, [$this, 'provideData']]; - yield [true, 'Psl\Type\is_callable']; - yield [false, [$this, 'non_existent_method']]; - yield [false, ['non_existent_class', 'static_method']]; - } -} diff --git a/tests/unit/Type/IsFloatTest.php b/tests/unit/Type/IsFloatTest.php deleted file mode 100644 index 0b1143f6..00000000 --- a/tests/unit/Type/IsFloatTest.php +++ /dev/null @@ -1,24 +0,0 @@ - yield false)(), true]; - } -} diff --git a/tests/unit/Type/IsNullTest.php b/tests/unit/Type/IsNullTest.php deleted file mode 100644 index 8d36f854..00000000 --- a/tests/unit/Type/IsNullTest.php +++ /dev/null @@ -1,24 +0,0 @@ -matches($a)) { $a = $a->toArray(); } - if (Type\is_object($b) && Type\is_instanceof($b, Collection\MapInterface::class)) { + if (Type\object(Collection\MapInterface::class)->matches($b)) { $b = $b->toArray(); } diff --git a/tests/unit/Type/MutableMapTypeTest.php b/tests/unit/Type/MutableMapTypeTest.php index f67e6c8e..bbc38591 100644 --- a/tests/unit/Type/MutableMapTypeTest.php +++ b/tests/unit/Type/MutableMapTypeTest.php @@ -99,11 +99,11 @@ public function getToStringExamples(): iterable */ protected function equals($a, $b): bool { - if (Type\is_object($a) && Type\is_instanceof($a, Collection\MutableMapInterface::class)) { + if (Type\object(Collection\MutableMapInterface::class)->matches($a)) { $a = $a->toArray(); } - if (Type\is_object($b) && Type\is_instanceof($b, Collection\MutableMapInterface::class)) { + if (Type\object(Collection\MutableMapInterface::class)->matches($b)) { $b = $b->toArray(); } diff --git a/tests/unit/Type/MutableVectorTypeTest.php b/tests/unit/Type/MutableVectorTypeTest.php index 9a333f5d..69076013 100644 --- a/tests/unit/Type/MutableVectorTypeTest.php +++ b/tests/unit/Type/MutableVectorTypeTest.php @@ -91,11 +91,11 @@ public function getToStringExamples(): iterable */ protected function equals($a, $b): bool { - if (Type\is_object($a) && Type\is_instanceof($a, Collection\MutableVectorInterface::class)) { + if (Type\object(Collection\MutableVectorInterface::class)->matches($a)) { $a = $a->toArray(); } - if (Type\is_object($b) && Type\is_instanceof($b, Collection\MutableVectorInterface::class)) { + if (Type\object(Collection\MutableVectorInterface::class)->matches($b)) { $b = $b->toArray(); } diff --git a/tests/unit/Type/UnionTypeTest.php b/tests/unit/Type/UnionTypeTest.php index 04cfc8b1..07e54f1a 100644 --- a/tests/unit/Type/UnionTypeTest.php +++ b/tests/unit/Type/UnionTypeTest.php @@ -74,4 +74,21 @@ public function getToStringExamples(): iterable 'null|vec|"php"|"still"|"alive"' ]; } + + public function testLiteralUnions(): void + { + $type = Type\union( + Type\literal_scalar('a'), + Type\literal_scalar('b'), + Type\literal_scalar('c'), + Type\literal_scalar('d'), + ); + + foreach (['a', 'b', 'c', 'd'] as $item) { + static::assertTrue($type->matches($item)); + static::assertSame($item, $type->assert($item)); + } + + static::assertFalse($type->matches('e')); + } } diff --git a/tests/unit/Type/VectorTypeTest.php b/tests/unit/Type/VectorTypeTest.php index 9e8e5368..1ca69c6a 100644 --- a/tests/unit/Type/VectorTypeTest.php +++ b/tests/unit/Type/VectorTypeTest.php @@ -91,11 +91,11 @@ public function getToStringExamples(): iterable */ protected function equals($a, $b): bool { - if (Type\is_object($a) && Type\is_instanceof($a, Collection\VectorInterface::class)) { + if (Type\object(Collection\VectorInterface::class)->matches($a)) { $a = $a->toArray(); } - if (Type\is_object($b) && Type\is_instanceof($b, Collection\VectorInterface::class)) { + if (Type\object(Collection\VectorInterface::class)->matches($b)) { $b = $b->toArray(); } diff --git a/tests/unit/Vec/KeysTest.php b/tests/unit/Vec/KeysTest.php index 4ef0fb2a..35af09e4 100644 --- a/tests/unit/Vec/KeysTest.php +++ b/tests/unit/Vec/KeysTest.php @@ -15,9 +15,7 @@ final class KeysTest extends TestCase */ public function testKeys(array $expected, iterable $iterable): void { - $result = Vec\keys($iterable); - - static::assertSame($expected, Iter\to_array_with_keys($result)); + static::assertSame($expected, Vec\keys($iterable)); } public function provideData(): iterable diff --git a/tests/unit/Vec/ReductionsTest.php b/tests/unit/Vec/ReductionsTest.php index 1dea6a3f..270d5aae 100644 --- a/tests/unit/Vec/ReductionsTest.php +++ b/tests/unit/Vec/ReductionsTest.php @@ -21,17 +21,35 @@ final class ReductionsTest extends TestCase * * @dataProvider provideData */ - public function testReductions(array $expected, iterable $iterable, callable $function, $initial): void + public function testReductions(array $expected, iterable $iterable, callable $function, mixed $initial): void { - $result = Vec\reductions($iterable, $function, $initial); - - static::assertSame($expected, Iter\to_array_with_keys($result)); + static::assertSame($expected, Vec\reductions($iterable, $function, $initial)); } + /** + * @return iterable, 1: iterable, 2: (function(int, int, int): int)}> + */ public function provideData(): iterable { - yield [[], [], static fn ($accumulator, $k, $v) => $accumulator, null]; - yield [[1, 3, 6], [1, 2, 3], static fn ($accumulator, $k, $v) => $accumulator + $v, 0]; - yield [[1, 3, 6], Iter\to_iterator([1, 2, 3]), static fn ($accumulator, $k, $v) => $accumulator + $v, 0]; + yield [ + [], + [], + static fn (int $accumulator, int $k, int $v): int => $accumulator, + 0, + ]; + + yield [ + [1, 3, 6], + [1, 2, 3], + static fn (int $accumulator, int $k, int $v): int => $accumulator + $v, + 0, + ]; + + yield [ + [1, 3, 6], + Iter\to_iterator([1, 2, 3]), + static fn (int $accumulator, int $k, int $v): int => $accumulator + $v, + 0, + ]; } }