Get the first item from the collection.

@param  \Closure   $callback
@param  mixed      $default
@return mixed|null
8397
public function first(Closure $callback = null, $default = null)
    {
        return count($this->items) > 0 ? reset($this->items) : null;
    }
1302922
public function container($container = null, Closure $callback = null)
    {
        $container = is_null($container) ? $this->defaultContainer : $container;

        if (!isset($this->containers[$container])) {
            $this->addContainer(
                $container,
                $this->getContainerTypes($container),
                $this->getContainerFormat($container),
                $this->getContainerFormats($container)
            );
        }

        if (is_callable($callback)) {
            $callback($this->containers[$container]);
        }

        return $this->containers[$container];
    }
522096
function chain(\Closure $func, $default = null)
    {
        $i    = 0;
        $prev = $default;
        foreach ($this->getIterator() as $key => $val) {
            if ($i++ !== 0)
                $prev = $func($val, $key, $prev);
            else
                // use default value of argument of given closure
                $prev = $func($val, $key);

        }

        return $prev;
    }
120053
public function start(Closure $callback)
    {
        $this->output = $callback;

        $this->cooldown();

        $this->process->start($callback);

        return $this;
    }
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;
    }
337603
public function sort(Closure $callback = null): CollectionInterface
    {
        $array = $this->toArray();

        if (is_null($callback)) {
            sort($array);
        } else {
            usort(
                $array,
                $callback
            );
        }

        return static::make($array);
    }
81069
public function previous(callable $callback = NULL) {
    $matches = [];
    foreach ($this->nodes as $node) {
      if ($match = $node->previous($callback)) {
        $matches[] = $match;
      }
    }
    return new NodeCollection($matches);
  }
990842
protected function resolveCriteriaGroupClosure(\Closure $callback): Query
    {
        if ($this->closureResolver === null) {
            return $this->makeCopyForCriteriaGroup()->apply($callback);
        } else {
            return $this->closureResolver->resolveCriteriaGroupClosure($callback);
        }
    }
1058813
public function first($default = NULL)
    {
        $first = $this->shift();
        if (! $first) {
            $first = $default;
        } else {
            $this->unshift($first);
        }
        return $first;
    }
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;
    }
1100071
public function sortMultiDimension(Closure $callback)
    {
        foreach ($this->items as &$sortable) {
            uasort($sortable, $callback);
        }
        unset($sortable);

        return $this;
    }
327198
public function get($callback = null)
    {
        $result = $this->acquire();

        if ($result && is_callable($callback)) {
            try {
                return $callback();
            } finally {
                $this->release();
            }
        }

        return $result;
    }
1253531
public function callback(Closure $callback)
    {
        foreach ($this->getInnerIterator() as $key => $value) {
            yield $callback($value, $key);
        }
    }
675103
public function when($name, callable $callback, callable $default = null, array $context = [])
    {
        if ($this->isActive($name, $context)) {
            return $callback($this->params($name), $context);
        } elseif ($default) {
            return $default($this->params($name), $context);
        }

        return $this;
    }
670883
public static function last($array, callable $callback = null, $default = null) {
        if (is_null($callback)) {
            return empty($array) ? Str::value($default) : end($array);
        }

        return static::first(array_reverse($array, true), $callback, $default);
    }
1053815
public function first(callable $callback = null, $default = null)
    {
        if (is_null($callback)) {
            return empty($this->items) ? $default : reset($this->items);
        }

        foreach ($this->items as $key => $value) {
            if (call_user_func($callback, $value, $key)) {
                return $value;
            }
        }

        return $default;
    }
165111
public function first()
    {
        $this->executeBeforeCallback();

        return count($this->items) > 0 ? reset($this->items) : null;
    }