Returns the first occurrence of a value that satisfies the predicate $func.

@param callable $func

@return mixed The first occurrence found
341089
public function find(callable $func)
    {
        $found = null;

        foreach ($this->elements as $key => $value) {
            if($func($value, $key)) {
                $found = $value;
                break;
            }
        }

        return $found;
    }
950354
public static function sorter($name, $func = null, $type = null)
    {
        if (!isset($func)) {
            $func = function ($a, $b) {
                if ($a == $b) {
                    return 0;
                }
                return $a < $b ? -1 : 1;
            };
        }
        
        if ($type == self::GETTER) {
            $method = 'get' . $name;
            return function ($a, $b) use ($method, $func) {
                return call_user_func($func, $a->$method(), $b->$method());
            };
        } elseif ($type == self::OBJ) {
            return function ($a, $b) use ($name, $func) {
                return call_user_func($func, $a->$name, $b->$name);
            };
        } else {
            return function ($a, $b) use ($name, $func) {
                return call_user_func($func, $a[$name], $b[$name]);
            };
        }
    }
938884
function filter($key=NULL,$func=NULL) {
        if (!$key)
            return array_keys($this->filter);
        if (!$func)
            return $this->filter[$key];
        $this->filter[$key]=$func;
    }
533217
protected function resolveFuncArgs(Func $func)
    {
        $params = $this->reader->read($func);

        $args = array();
        foreach ($params as $param) {

            $name = $param->name;
            $inst = $this->tryService($name);

            if (!$inst && $param->hasDefault) {
                $args[$name] = $param->default;
            } else if ($inst && $param->type && $this->checker->validate($param->type, $inst)) {
                $args[$name] = $inst;
            } else if ($inst && $param->type && !$this->checker->validate($param->type, $inst)) {
                throw new ResolutionException("Parameter type is not compatible with service '$name'");
            } else if ($inst) {
                $args[$name] = $inst;
            } else {
                throw new ResolutionException("Could not resolve parameter '$name'");
            }
        }

        return $args;
    }
459760
function first(callable $closure = null) {
        if($closure === null) {
            if(empty($this->data)) {
                return null;
            }
            
            $keys = \array_keys($this->data);
            return ($this->data[$keys[0]] ?? null);
        }
        
        foreach($this->data as $key => $val) {
            $feed = (bool) $closure($val, $key);
            if($feed) {
                return $val;
            }
        }
        
        return null;
    }
505093
public function filter(callable $func = null, $flag = null)
    {
        $answer = new Filter($this->toHArray());
        return new static((new HArray($answer->filter($func, $flag)))->toHString());
    }
205595
public function takeUntil(callable $predicate)
    {
        return $this->takeWhile(
            function ($value, $key, $iterable) use ($predicate) {
                return !$predicate($value, $key, $iterable);
            }
        );
    }
410290
public function Sort( $Func = null )
	{
		$sorted = $this->repository;

		$Func = new Expression( $Func );

		usort( $sorted , [ $Func , 'execute' ] );

		return $this
					->getClone()
					->setRepository( $sorted );
	}
452574
public function Where( $Func )
	{

		if ( $Func != null ){

			$repo = array();

			$Func = new Expression( $Func );

			foreach ( $this->repository as $item )
				if ( $Func->execute( $item ) )
					$repo[] = $item;

		} else {

			$repo = $this->repository;

		}

		return $this->getClone()->setRepository( $repo );

	}
1128018
public function find(callable $predicate)
    {
        $result = Maybe::nothing();

        $this->each(
            function ($value, $key) use (
                $predicate,
                &$result
            ) {
                if ($predicate($value, $key, $this)) {
                    $result = Maybe::just($value);

                    return false;
                }

                return true;
            }
        );

        return $result;
    }
1202478
public function first(callable $conditions = null)
    {
        $array = $this->convertArray($this);

        if ($conditions) {
            foreach ($array as $key => $value) {
                if ($conditions($value, $key)) {
                    return $value;
                }
            }

            return null;
        }

        return $array[array_key_first($array)];
    }
267058
public function callback($func) {
        if (!$this->_isValid) {
            return $this;
        }
        $this->_isValid = (bool) $func($this->_unsafeVar);
        return $this;
    }
798206
public function add($func)
    {
        ValidationException::assert(
            function () use ($func) {
                return !is_callable($func);
            },
            'function is not callable'
        );
        $this->func[] = $func;
        return $this;
    }
371001
public function each($func)
    {
        $data = [];
        foreach ($this->_nodes as $index => $selector) {
            $data[$index] = $func($selector, $index);
        }

        return $data;
    }
926374
public function map(Closure $func)
    {
        return new static($this->type, $this->elements->map($func)->toArray());
    }
630446
public function map(Closure $func)
    {
        $this->guardAgainstInvalidGivenType();
        $elements = $this->collection->map($func)->toArray();
        $newCollection = $this->create();
        foreach ($elements as $key => $element) {
            try {
                $newCollection->set($key, $element);
            } catch (InvalidArgumentException $e) {
                // do nothing, because the mapped item is not instance of type
            }
        }

        return $newCollection;
    }
115063
public function map(Closure $func)
    {
        $clone = clone $this;

        $clone->data = array_map($func, $this->data);
        $clone->updateBody();

        return $clone;
    }