添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

See: #1125

Surely these should be more like sort() :

https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Collection.php#L199

public function sort(Closure $callback)
    uasort($this->items, $callback);
    return $this;

Like so:

https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Collection.php#L177

public function map(Closure $callback)
    $this->items = array_map($callback, $this->items);
    return $this;

https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Collection.php#L188

public function filter(Closure $callback)
    $this->items = array_filter($this->items, $callback);
    return $this;

Otherwise you lose any manipulation you have done previously... Thoughts?

return $voicemails;

Both filter() and map() calls would be moot as they will be returning their own objects. You would have to do this to get it work properly:

$voicemails = $this->request('voicemail_count_url', array(
    // code
$voicemails = $voicemails->filter(function($voicemail) {
    // code
$voicemails = $voicemails->map(function($voicemail) {
    /// code...
return $voicemails;

Yes because those are fluent methods, you can just write it like that :

return $this->request('voicemail_count_url', array(
    // code
))->filter(function($voicemail) {
    // code
})->map(function($voicemail) {
    /// code...
          

Actually, I think both map() and filter() should be kept how they are (for a few reasons, sometimes you want new collections, also backwards compatibility)

However, map() has a similar function called each() which works on the current object and does not return a new one. I would suggest we add a similar companion function for filter().

https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Collection.php#L158-L180

@Kindari Agreed. Although the descriptions for each() and map() should probably be updated to reflect what they actually do.

Maybe filtered() as the filter() companion?