Skip to content

Commit

Permalink
refactor: Remove Collection::with constructor.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: yes

Signed-off-by: Pol Dellaiera <pol.dellaiera@protonmail.com>
  • Loading branch information
drupol committed Oct 27, 2020
1 parent 1aae097 commit 90c732c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 102 deletions.
30 changes: 0 additions & 30 deletions docs/pages/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,6 @@ Another example
$even = Collection::range(0, \INF, 2);
$odd = Collection::range(1, \INF, 2);
with
~~~~

.. warning:: Will be deprecated soon.
Use ``fromCallable``, ``fromIterable``, ``fromResource``, ``fromString`` instead.

Create a collection with the provided data.

Signature: ``Collection::with($data = [], ...$parameters);``

.. code-block:: php
// With an iterable
$collection = Collection::with(['a', 'b']);
// With a string
$collection = Collection::with('string');
$callback = static function () {
yield 'a';
yield 'b';
yield 'c';
};
// With a callback
$collection = Collection::with($callback);
// With a resource/stream
$collection = Collection::with(fopen( __DIR__ . '/vendor/autoload.php', 'r'));
Methods (operations)
--------------------

Expand Down
56 changes: 3 additions & 53 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public function it_can_be_constructed_from_a_stream(): void

$stream = imagecreate(100, 100);

$this::with($stream)
->count()
->shouldReturn(1);
$this
->shouldThrow(InvalidArgumentException::class)
->during('fromResource', [$stream]);
}

public function it_can_be_constructed_from_a_string(): void
Expand Down Expand Up @@ -2785,56 +2785,6 @@ public function it_can_use_times_without_a_callback(): void
->shouldIterateAs([]);
}

public function it_can_use_with(): void
{
$input = ['a' => 'A', 'b' => 'B', 'c' => 'C'];

$generator = static function () {
yield 'a' => 'A';

yield 'b' => 'B';

yield 'c' => 'C';
};

$this::with($input)
->shouldIterateAs($generator());

$this::with($generator)
->shouldIterateAs($generator());

$this::with('abc')
->shouldIterateAs(['a', 'b', 'c']);

$this::with('abc def', ' ')
->shouldIterateAs(['abc', 'def']);

$stream = static function () {
$stream = fopen(__DIR__ . '/../../../.editorconfig', 'rb');

while (false !== $chunk = fgetc($stream)) {
yield $chunk;
}

fclose($stream);
};

$this::with($stream)
->explode("\n")
->last()
->unwrap()
->implode()
->shouldIterateAs([14 => 'indent_size = 4']);

$stream = fopen(__DIR__ . '/../../fixtures/sample.txt', 'rb');

$this::with($stream)
->shouldIterateAs(['a', 'b', 'c']);

$this::with(1)
->shouldIterateAs([1]);
}

public function it_can_window(): void
{
$this::fromIterable(range('a', 'z'))
Expand Down
5 changes: 0 additions & 5 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,6 @@ public function window(int $size): CollectionInterface
return $this->pipe(Window::of()($size));
}

public static function with($data = [], ...$parameters): CollectionInterface
{
return new self($data, ...$parameters);
}

public function words(): CollectionInterface
{
return $this->pipe(Words::of());
Expand Down
14 changes: 0 additions & 14 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,4 @@ public static function fromString(string $string, string $delimiter = ''): Colle
* @psalm-return \loophp\collection\Iterator\ClosureIterator<TKey, T>
*/
public function getIterator(): ClosureIterator;

/**
* @psalm-template NewTKey
* @psalm-template NewTKey of array-key
* @psalm-template NewT
*
* Create a collection with the data.
*
* @param mixed $data
* @param mixed ...$parameters
*
* @psalm-return \loophp\collection\Contract\Collection<NewTKey, NewT>
*/
public static function with($data = [], ...$parameters): Collection;
}

0 comments on commit 90c732c

Please sign in to comment.