Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection: remove static factory methods from contract #78

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ public function duplicate(): CollectionInterface
return new self(Duplicate::of(), $this->getIterator());
}

/**
* Create a new instance with no items.
*
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*/
public static function empty(): CollectionInterface
{
return self::fromIterable([]);
Expand Down Expand Up @@ -362,6 +369,13 @@ public function frequency(): CollectionInterface
return new self(Frequency::of(), $this->getIterator());
}

/**
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*
* @param mixed ...$parameters
*/
public static function fromCallable(callable $callable, ...$parameters): self
{
return new self($callable, ...$parameters);
Expand All @@ -378,6 +392,14 @@ public static function fromFile(string $filepath): self
);
}

/**
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*
* @param iterable<mixed> $iterable
* @psalm-param iterable<NewTKey, NewT> $iterable
*/
public static function fromIterable(iterable $iterable): self
{
return new self(
Expand All @@ -391,6 +413,9 @@ public static function fromIterable(iterable $iterable): self
);
}

/**
* @param resource $resource
*/
public static function fromResource($resource): self
{
return new self(
Expand Down
37 changes: 0 additions & 37 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,43 +331,6 @@ interface Collection extends
Wrapable,
Zipable
{
/**
* Create a new instance with no items.
*
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*/
public static function empty(): self;

/**
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*
* @param mixed ...$parameters
*/
public static function fromCallable(callable $callable, ...$parameters): self;

public static function fromFile(string $filepath): self;

/**
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*
* @param iterable<mixed> $iterable
* @psalm-param iterable<NewTKey, NewT> $iterable
*/
public static function fromIterable(iterable $iterable): self;

/**
* @param resource $resource
*/
public static function fromResource($resource): self;

public static function fromString(string $string, string $delimiter = ''): self;

/**
* @psalm-return \Iterator<TKey, T>
*/
Expand Down