Skip to content

[12.x] Add documentation for higher order static calls on collections #10478

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

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 35 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Extending Collections](#extending-collections)
- [Available Methods](#available-methods)
- [Higher Order Messages](#higher-order-messages)
- [Higher Order Static Calls](#higher-order-static-calls)
- [Lazy Collections](#lazy-collections)
- [Introduction](#lazy-collection-introduction)
- [Creating Lazy Collections](#creating-lazy-collections)
Expand Down Expand Up @@ -3994,6 +3995,40 @@ $users = User::where('group', 'Development')->get();
return $users->sum->votes;
```

<a name="higher-order-static-calls"></a>
## Higher Order Static Calls

Collections also provide support for "higher order static calls", which are short-cuts for calling static methods elegantly if you’re storing class names in collections.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to use an actual apostrophe here 😉

Suggested change
Collections also provide support for "higher order static calls", which are short-cuts for calling static methods elegantly if youre storing class names in collections.
Collections also provide support for "higher order static calls", which are short-cuts for calling static methods elegantly if you're storing class names in collections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you're not.

That's what I meant 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if "shortcut" isn't the more common version 🤔 but I'm not a native speaker, so 🤷🏻‍♂️

Suggested change
Collections also provide support for "higher order static calls", which are short-cuts for calling static methods elegantly if you’re storing class names in collections.
Collections also provide support for "higher order static calls", which are shortcuts for calling static methods elegantly if you’re storing class names in collections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same tone that we used in the section above that one, see: Higher Order Messages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In dusk docs we used both shortcuts and short-cuts, so I will open a PR to unify that across the docks.

Thank you for this.


```php
class Transformer1
{
public static function transform(string $name): string
{
return strtoupper($name);
}
}

class Transformer2
{
public static function transform(string $name): string
{
return strtolower($name);
}
}

$transformers = collect([Transformer1::class, Transformer2::class]);

$results = $transformers->map->transform('taylor');

$results->dd();

// array:2 [
// 0 => "TAYLOR"
// 1 => "taylor"
// ]
```

<a name="lazy-collections"></a>
## Lazy Collections

Expand Down