Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Nov 22, 2021
1 parent 1003341 commit 2cac2fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The MIT License (MIT)
````# The MIT License (MIT)
Copyright (c) Spatie bvba <[email protected]>
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ The package will automatically register itself.
- [`firstOrFail`](#firstorfail)
- [`firstOrPush`](#firstorpush)
- [`fromPairs`](#frompairs)
- [`getDeeply`](#getdeeply)
- [`glob`](#glob)
- [`groupByModel`](#groupbymodel)
- [`head`](#head)
Expand All @@ -66,6 +65,7 @@ The package will automatically register itself.
- [`none`](#none)
- [`paginate`](#paginate)
- [`parallelMap`](#parallelmap)
- [`path`](#path)
- [`pluckMany`](#pluckmany)
- [`pluckToArray`](#plucktoarray)
- [`prioritize`](#prioritize)
Expand Down Expand Up @@ -354,23 +354,6 @@ $collection = collect([['a', 'b'], ['c', 'd'], ['e', 'f']])->fromPairs();
$collection->toArray(); // returns ['a' => 'b', 'c' => 'd', 'e' => 'f']
```

### `getDeeply`

Returns an item from the collection with multidimensional data using "dot" notation.
Works the same way as native Collection's `pull` method, but without removing an item from the collection.

```php
$collection = new Collection([
'foo' => [
'bar' => [
'baz' => 100,
]
]
]);

$collection->getDeeply('foo.bar.baz') // 100
```

### `glob`

Returns a collection of a `glob()` result.
Expand Down Expand Up @@ -611,6 +594,23 @@ $pageSources = collect($urls)->parallelMap(function($url) {

This helps to reduce the memory overhead, as the default worker pool limit is `32` (as defined in `amphp/parallel`). Using fewer worker threads can significantly reduce memory and processing overhead, in many cases. Benchmark and customise the worker thread limit to suit your particular use-case.

### `path`

Returns an item from the collection with multidimensional data using "dot" notation.
Works the same way as native Collection's `pull` method, but without removing an item from the collection.

```php
$collection = new Collection([
'foo' => [
'bar' => [
'baz' => 'value',
]
]
]);

$collection->path('foo.bar.baz') // 'value'
```

### `pluckMany`

Returns a collection with only the specified keys.
Expand Down
2 changes: 1 addition & 1 deletion src/CollectionMacroServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ private function macros(): array
'firstOrPush' => \Spatie\CollectionMacros\Macros\FirstOrPush::class,
'fourth' => \Spatie\CollectionMacros\Macros\Fourth::class,
'fromPairs' => \Spatie\CollectionMacros\Macros\FromPairs::class,
'getDeeply' => \Spatie\CollectionMacros\Macros\GetDeeply::class,
'getNth' => \Spatie\CollectionMacros\Macros\GetNth::class,
'glob' => \Spatie\CollectionMacros\Macros\Glob::class,
'groupByModel' => \Spatie\CollectionMacros\Macros\GroupByModel::class,
Expand All @@ -48,6 +47,7 @@ private function macros(): array
'none' => \Spatie\CollectionMacros\Macros\None::class,
'paginate' => \Spatie\CollectionMacros\Macros\Paginate::class,
'parallelMap' => \Spatie\CollectionMacros\Macros\ParallelMap::class,
'path' => \Spatie\CollectionMacros\Macros\Path::class,
'pluckMany' => \Spatie\CollectionMacros\Macros\PluckMany::class,
'pluckToArray' => \Spatie\CollectionMacros\Macros\PluckToArray::class,
'prioritize' => \Spatie\CollectionMacros\Macros\Prioritize::class,
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/GetDeeply.php → src/Macros/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @return mixed
*/
class GetDeeply
class Path
{
public function __invoke()
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Macros/GetDeeplyTest.php → tests/Macros/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Collection;
use Spatie\CollectionMacros\Test\TestCase;

class GetDeeplyTest extends TestCase
class PathTest extends TestCase
{
/** @test */
public function it_retrieves_item_from_collection()
Expand All @@ -14,7 +14,7 @@ public function it_retrieves_item_from_collection()

$this->assertSame(
'foo',
$collection->getDeeply(0)
$collection->path(0)
);
}

Expand All @@ -31,7 +31,7 @@ public function it_retrieves_item_from_collection_using_dot_notation()

$this->assertSame(
100,
$collection->getDeeply('foo.bar.baz')
$collection->path('foo.bar.baz')
);
}

Expand All @@ -40,7 +40,7 @@ public function it_doesnt_remove_item_from_collection()
{
$collection = new Collection(['foo', 'bar']);

$collection->getDeeply(0);
$collection->path(0);

$this->assertEquals(
[
Expand All @@ -58,7 +58,7 @@ public function it_returns_default()

$this->assertSame(
'foo',
$collection->getDeeply(0, 'foo')
$collection->path(0, 'foo')
);
}
}

0 comments on commit 2cac2fb

Please sign in to comment.