Skip to content

Commit

Permalink
Minor optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed May 29, 2020
1 parent 7b71cbc commit 5c1f248
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function pluck($pluck, $default = null): BaseInterface
*/
public function prepend(...$items): BaseInterface
{
return $this->run(new Prepend($items));
return $this->run(new Prepend(...$items));
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Operation/Prepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function on(iterable $collection): Closure
$items = $this->items;

return static function () use ($items, $collection): Generator {
[$items] = $items;

foreach ($items as $item) {
yield $item;
}
Expand Down
12 changes: 7 additions & 5 deletions src/Operation/RSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public function on(iterable $collection): Closure
{
$probability = $this->probability;

$callback = static function ($item) use ($probability): bool {
return (mt_rand() / mt_getrandmax()) < $probability;
};

return (new Filter($callback))->on($collection);
return (
new Filter(
static function () use ($probability): bool {
return (mt_rand() / mt_getrandmax()) < $probability;
}
)
)->on($collection);
}
}

0 comments on commit 5c1f248

Please sign in to comment.