Get filtered results by function

A row will go through if function return true

@param function $cb Callback function

@return DataSore New datastore containing filtered results.
967148
public function filterByFunc($cb)
    {
        //method filters the collection using the given callback, keeping only those rows that pass a given truth test
        $dstore = new DataStore;
        $dstore->meta($this->metaData);
        foreach ($this->rows as $index=>$row) {
            if ($cb($row, $index)===true) {
                $dstore->append($row);
            }
        }
        return $dstore;
    }
213098
public function countBy($callback = null)
    {
        if (is_null($callback)) {
            $callback = function ($value) {
                return $value;
            };
        }

        return new static($this->groupBy($callback)->map(function ($value) {
            return $value->count();
        }));
    }
584266
protected function doQuery($callback)
    {
        $previousMethod = debug_backtrace(null, 2)[1];
        $methodName = $previousMethod['function'];
        $arguments = $previousMethod['args'];

        $result = $this->doBeforeQuery($callback, $methodName, $arguments);

        return $this->doAfterQuery($result, $methodName, $arguments);
    }
737089
public function find(callable $cb)
    {
        foreach ($this->sfa as $i => $el) {
            if ($cb($el, $i, $this)) return $el;
        }
    }
875414
public function filterByCallback($callback)
    {
        if (!is_callable($callback)) {
            throw new LogicException(sprintf(
                "SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
                gettype($callback)
            ));
        }

        $output = static::create();

        foreach ($this as $item) {
            if (call_user_func($callback, $item, $this)) {
                $output->push($item);
            }
        }

        return $output;
    }
2310
public function byFunction(
        string $function,
        string $order
    ): SortBy {
        $this->sortsBy[] = [
            'type' => self::TYPE_FUNCTION,
            'function' => $function,
            'order' => $order,
        ];

        return $this;
    }
1290133
public function each($cb)
    {
        foreach ($this->rows as $index=>$row) {
            $result = $cb($row, $index);
            if (is_array($result)) {
                $this->rows[$index] = $result;
            } else if ($result===false) {
                break;
            }
        }
        return $this;
    }
877017
function (cb) {
        return function() {
            var args = Array.prototype.slice.call(arguments);
            var next = args.pop();

            args.push(function() {
                // if (err) return next(err);
                var iargs = Array.prototype.slice.call(arguments);

                next.apply(this, iargs);
            });
            cb.apply(this, args);
        };
    }
455648
public function each(callable $callback, $count = 1000)
    {
        $result = $this->getBuilder()->each($callback, $count);

        // Reset query builder
        $this->resetBuilder();

        return $result;
    }
797045
public function filter( $callback ) {

			$result = [];

			if ( is_callable( $callback ) ) {

				for ( $i=0; $i<$this->len; $i++ ) {
					if ( call_user_func( $callback, $this->items[$i], $i, $this ) ) {
						$result[] = &$this->items[$i];
					}
				}

			}

			$myName = get_class();

			return new $myName( $result );

		}
688191
public function get( $first = TRUE, $orders = array(), $limits = array() ){
		$this->validateFocus();
		$data = array();
		$conditions	= $this->getConditionQuery( array(), TRUE, TRUE, FALSE );						//  render WHERE clause if needed, cursored, without functions
		$orders		= $this->getOrderCondition( $orders );
		$limits		= $this->getLimitCondition( $limits );
		$columns	= $this->getColumnEnumeration( $this->columns );								//  get enumeration of masked column names
		$query		= 'SELECT '.$columns.' FROM '.$this->getTableName().' WHERE '.$conditions.$orders.$limits;

		$resultSet	= $this->dbc->query( $query );
		if( !$resultSet )
			return $first ? NULL : array();
		$resultList	= $resultSet->fetchAll( $this->getFetchMode() );
		if( $first )
			return $resultList ? $resultList[0] : NULL;
		return $resultList;
	}
178117
public function filter(callable $callback = null): CollectionInterface
    {
        if (!$callback) {
            $callback = function ($item) {
                return (bool)$item;
            };
        }

        return $this->wrap(function (Iterator $data) use ($callback) {
            foreach ($data as $key => $item) {
                if ($callback($item, $key)) {
                    yield $key => $item;
                }
            }
        });
    }
554044
private function aggregate($type, $cb = null)
    {
        $data = [];

        $this->recursive(
            $this->storage,
            function ($value) use (& $data) {
                if (is_numeric($value)) {
                    $data[] = $value;
                }
            }
        );

        $r = call_user_func_array($type, $data);

        if (is_callable($cb)) {
            call_user_func_array($cb, [$r]);
        }

        return $r;
    }
416927
public function filter(callable $callback = null)
    {
        if ($callback === null) {
            return new static(\array_filter($this->all()));
        }

        return new static(\array_filter($this->all(), $callback));
    }
155064
public function sort($callback)
    {
        $newCollection = clone $this;
        \uasort($newCollection->arrCollection, $callback);

        $newCollection->arrCollection = \array_values($newCollection->arrCollection);

        return $newCollection;
    }
630554
public function getQueryResults($limit = null)
    {
        if (isset($limit)) {
            $this->queryBuilder->setMaxResults($limit);
        }
        
        if (!$this->queryBuilder->getDQLPart('orderBy')) {
            $this->queryBuilder->orderBy('a.createdAt', 'ASC');
        }

        return $this->queryBuilder->getQuery()->getResult();
    }
3770
public function transition(callable $cb)
    {
        $where = $this->where;

        $data = $this->get();

        if (call_user_func_array($cb, [$data]) === true) {
            $this->where = $where;
        }

        return $this;
    }