Syntax: count ()
If source iterator implements {@link Countable}, that implementation is used to obtain the count of elements. Otherwise, this method determines the count.
Syntax: count (predicate {(v, k) ==> result})
Returns a number that represents how many elements in the specified sequence satisfy a condition.
public function count($predicate = null)
{
$it = $this->getIterator();
if ($it instanceof \Countable && $predicate === null) {
return count($it);
}
$predicate = Utils::createLambda($predicate, 'v,k', Functions::$value);
$count = 0;
foreach ($it as $k => $v) {
if ($predicate($v, $k)) {
$count++;
}
}
return $count;
}