Return the first element in an array passing a given truth test.

@param array   $values
@param Closure $callback
@param mixed   $default

@return mixed
762869
public static function first(array $values, Closure $callback, $default = null)
    {
        foreach ($values as $key => $value) {
            if (call_user_func($callback, $key, $value)) {
                return $value;
            }
        }

        return $default instanceof Closure ? call_user_func($default, $values) : $default;
    }
573902
public static function find(array $data, callable $callback = null, $keepKey = false, $offset = null, $limit = null)
    {
        $results = [];
        $i = 0;
        $c = 0;

        $callback = null === $callback ? 'is_null' : $callback;

        foreach ($data as $key => $value) {
            // If use global function, send only value as argument.
            if (is_string($callback)) {
                $r = $callback($value);
            } else {
                $r = $callback($value, $key);
            }

            if ($r) {
                if ($offset !== null && $offset > $i) {
                    continue;
                }

                if ($limit !== null && $c >= $limit) {
                    break;
                }

                $results[$key] = $value;
                $c++;
            }

            $i++;
        }

        return $keepKey ? $results : array_values($results);
    }
1277488
public static function build($array, Closure $callback)
	{
		$results = array();

		foreach ($array as $key => $value)
		{
			list($innerKey, $innerValue) = call_user_func($callback, $key, $value);

			$results[$innerKey] = $innerValue;
		}

		return $results;
	}
343086
public static function deserialize(array $values, array $callbacks = []): array
    {
        $deserializedData = [];
        foreach ($values as $property => $value) {
            if (isset($callbacks[$property])) {
                if (is_array($value) && ArrayHelper::isNumericallyIndexed($value)) {
                    $value = array_map($callbacks[$property], $value);
                } elseif ($value !== null) {
                    // if $value is null, we don't call the callable, since its type-hint may then cause a fatal error
                    $value = $callbacks[$property]($value);
                }
            }

            $deserializedData[$property] = $value;
        }

        return $deserializedData;
    }
724628
protected static function callBoundMethod($container, $callback, $default)
    {
        if (! is_array($callback)) {
            return $default instanceof Closure ? $default() : $default;
        }

        // Here we need to turn the array callable into a Class@method string we can use to
        // examine the container and see if there are any method bindings for this given
        // method. If there are, we can call this method binding callback immediately.
        $method = static::normalizeMethod($callback);

        if ($container->hasMethodBinding($method)) {
            return $container->callMethodBinding($method, $callback[0]);
        }

        return $default instanceof Closure ? $default() : $default;
    }
315906
public static function getValue($data, $key, $defaultvalue = false)
    {
        //        if (is_a($data, ChainedArray::class)) {
        //            $result = $data->get($key);
        //
        //            if (is_a($result, ChainedArray::class)) {
        //                /** ChainedArray $result */
        //                return ($result->count()==0) ? $defaultvalue : $result;
        //            } else {
        //                return $result;
        //            }
        //        } else
        if (is_array($data)) {
            return (array_key_exists($key, $data)) ? $data[$key] : $defaultvalue;
        } else {
            return $defaultvalue;
        }
    }
51810
public static function first( $array, $callback, $default = NULL )
    {
        foreach ( $array as $key => $value )
        {
            if ( call_user_func( $callback, $key, $value ) ) return $value;
        }

        return Util::value( $default );
    }
65223
public function call($callback, array $parameters = [], $defaultMethod = null)
    {
        return BoundMethod::call($this, $callback, $parameters, $defaultMethod);
    }
410537
public static function getChildByArray(array $keys, array $values, $default = null) {
		switch (count($keys)) {
			case 0:
				return $values;
			case 1:
				return array_key_exists($keys[0], $values) ? $values[$keys[0]] : $default;
			case 2:
				return isset($values[$keys[0]][$keys[1]]) ? $values[$keys[0]][$keys[1]] : $default;
			case 3:
				return isset($values[$keys[0]][$keys[1]][$keys[2]]) ? $values[$keys[0]][$keys[1]][$keys[2]] : $default;
			case 4:
				return isset($values[$keys[0]][$keys[1]][$keys[2]][$keys[3]]) ? $values[$keys[0]][$keys[1]][$keys[2]][$keys[3]] : $default;
			default:
				return isset($values[$keys[0]]) ? self::getChildByArray(array_slice($keys, 1), $values[$keys[0]], $default) : $default;
		}
	}
981337
public function getValue(string $name, $default = null)
    {
        $value = Arr::getByPath($this->config, $name, $default);

        if ($value && $value instanceof \Closure) {
            $value = $value();
        }

        return $value;
    }
8397
public function first(Closure $callback = null, $default = null)
    {
        return count($this->items) > 0 ? reset($this->items) : null;
    }
1287814
public function rememberManyForever(array $keys, Closure $callback)
    {
        $values = $this->getMany($keys);

        $items = Arr::where($values, function ($key, $value) {
            return is_null($value);
        });

        if (! empty($items)) {
            $items = array_combine(array_keys($items), $callback(array_keys($items)));

            $this->foreverMany($items);

            $values = array_replace($values, $items);
        }

        return $values;
    }
484137
protected function _addOrSetValues($values,$callback) {
		$count=$this->count();
		if (!\is_array($values)) {
			$values=\array_fill(0, $count, $values);
		} else {
			if (JArray::isAssociative($values) === true) {
				$values=\array_values($values);
			}
		}
		$count=\min(\sizeof($values), $count);

		for($i=0; $i < $count; $i++) {
			$cell=$this->content[$i];
			$callback($cell,$values[$i]);
		}
		return $this;
	}
874914
public function in($field, array $values)
    {
        return function ($object) use ($field, $values) {
            return in_array(ClosureExpressionBuilder::getObjectFieldValue($object, $field), $values);
        };
    }
977116
public function whereFirstOrDefault($where, $default=null)
    {
        $where = LambdaUtils::toConditionCallable($where);
        foreach($this as $record)
        {
            if(call_user_func($where, $record))
            {
                return $record;
            }
        }
        return $default;
    }
171172
public function each($data = [], Closure $callback)
    {
        $factory = $this->getFactory();
        $results = array();
        foreach ($data as $item) {
            $callback($factory, $item);
            $results[] = $factory->getResults();
        }

        return $results;
    }
1178155
protected function getFirstFromProviders(callable $callable, $default = null)
    {
        $values = array_filter(array_map($callable, $this->providers));

        return empty($values) ? $default : current($values);
    }