original_string: 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();
      }
code: 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();
      }
code_tokens: 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 ( ) ; }
docstring: Get the median of a given key.
  
  @param  null $key
  
  @return mixed
docstring_tokens: Get the median of a given key .