public function median($key = null)
    {
        $count = $this->count();

        if ($count == 0) {

            return;
        }

        $values = $this->with(isset($key) ? $this->pluck($key) : $this)->sort()->values();
        $middle = (int) ($count / 2);

        if ($count % 2) {

            return $values->get($middle);
        }

        return (new static([$values->get($middle - 1), $values->get($middle)]))->average();
    }