Skip to content

Commit

Permalink
fix: Update return types of Implode and Unlines operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 30, 2021
1 parent a1964f4 commit 05bbf8e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Contract/Operation/Implodeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Implodeable
*
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#implode
*
* @return Collection<int, string>
* @return Collection<TKey, string>
*/
public function implode(string $glue = ''): Collection;
}
6 changes: 3 additions & 3 deletions src/Operation/Implode.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ final class Implode extends AbstractOperation
/**
* @pure
*
* @return Closure(string): Closure(Iterator<TKey, T>): Generator<int, string>
* @return Closure(string): Closure(Iterator<TKey, T>): Generator<TKey, string>
*/
public function __invoke(): Closure
{
return
/**
* @return Closure(Iterator<TKey, T>): Generator<int, string>
* @return Closure(Iterator<TKey, T>): Generator<TKey, string>
*/
static function (string $glue): Closure {
$reducer =
Expand All @@ -41,7 +41,7 @@ static function (string $glue): Closure {
*/
static fn (string $carry, $item): string => $carry .= $item;

/** @var Closure(Iterator<TKey, T>): Generator<int, string> $pipe */
/** @var Closure(Iterator<TKey, T>): Generator<TKey, string> $pipe */
$pipe = Pipe::of()(
Intersperse::of()($glue)(1)(0),
Drop::of()(1),
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Unlines.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class Unlines extends AbstractOperation
/**
* @pure
*
* @return Closure(Iterator<TKey, (T|string)>): Generator<TKey, string, mixed, void>
* @return Closure(Iterator<TKey, (T|string)>): Generator<TKey, string>
*/
public function __invoke(): Closure
{
Expand Down
32 changes: 32 additions & 0 deletions tests/static-analysis/implode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

include __DIR__ . '/../../vendor/autoload.php';

use loophp\collection\Collection;
use loophp\collection\Contract\Collection as CollectionInterface;

/**
* @param CollectionInterface<int, string> $collection
*/
function implode_checkListString(CollectionInterface $collection): void
{
}

/**
* @param CollectionInterface<string, string> $collection
*/
function implode_checkMapInt(CollectionInterface $collection): void
{
}

$input = range('a', 'e');

implode_checkListString(Collection::fromIterable($input)->implode(','));
implode_checkMapInt(Collection::fromIterable(array_combine($input, $input))->implode(','));

0 comments on commit 05bbf8e

Please sign in to comment.