Skip to content

Commit

Permalink
Revert "Add Collection::reject() method"
Browse files Browse the repository at this point in the history
This reverts commit d4c05e4.
  • Loading branch information
thanapongp committed Sep 5, 2017
1 parent d4c05e4 commit c2404cc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 56 deletions.
21 changes: 0 additions & 21 deletions src/mako/utility/Collection.php
Expand Up @@ -339,25 +339,4 @@ public function filter(callable $callable = null)

return new static(array_filter($this->items, $callable));
}

/**
* Reject item based on the given criteria.
*
* @param mixed $criteria Filter
* @return \mako\utility\Collection
*/
public function reject($criteria)
{
if (! is_callable($criteria)) {
return $this->reject(function($value) use ($criteria)
{
return $value === $criteria;
});
}

return $this->map(function($value, $key) use ($criteria)
{
return $criteria($value, $key) ? null : $value;
})->filter();
}
}
35 changes: 0 additions & 35 deletions tests/unit/utility/CollectionTest.php
Expand Up @@ -484,39 +484,4 @@ public function testFilter()
$this->assertSame([1, 2, 3], $collection->getValues());

}

/**
*
*/
public function testReject()
{
$collection = new Collection([1, 2, 3]);

$result = $collection->reject(function($value)
{
return $value > 2;
});

$this->assertSame([1, 2], $result->getItems());
$this->assertSame([1, 2, 3], $collection->getItems());

// Also works with key
$collection = new Collection(['foo' => 1, 'bar' => 2, 3 => 3]);

$result = $collection->reject(function($value, $key)
{
return is_int($key);
});

$this->assertSame(['foo' => 1, 'bar' => 2], $result->getItems());
$this->assertSame(['foo' => 1, 'bar' => 2, 3 => 3], $collection->getItems());

// Also works with single value
$collection = new Collection([1, 2, 3]);

$result = $collection->reject(3);

$this->assertSame([1, 2], $result->getItems());
$this->assertSame([1, 2, 3], $collection->getItems());
}
}

0 comments on commit c2404cc

Please sign in to comment.