Skip to content

Commit

Permalink
Add filter and without methods
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshi2889 <rick.2889@gmail.com>
  • Loading branch information
NanoSector committed Jun 28, 2017
1 parent f1ced42 commit bf97b49
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ public function __construct(\Closure $valueValidator, array $initialValues = [])
$this->offsetSet($key, $initialValue);
}

/**
* @param \Closure $condition
*
* @return Collection
*/
public function filter(\Closure $condition): Collection
{
$collection = new self($this->validator);
foreach ($this->values() as $offset => $value)
if ($condition($value))
$collection->offsetSet($offset, $value);

return $collection;
}

/**
* @param \Closure $condition
*
* @return Collection
*/
public function without(\Closure $condition): Collection
{
$collection = new self($this->validator);
foreach ($this->values() as $offset => $value)
if (!$condition($value))
$collection->offsetSet($offset, $value);

return $collection;
}

/**
* @param mixed $value
*
Expand Down

0 comments on commit bf97b49

Please sign in to comment.