code: public function groupBy($metric)
      {        
          $collection = $this->getIterator();
  
          // Create a new collection which we'll populate with our grouped data
          $GroupedCollection = new self();
  
          foreach($collection as $key => $item) {
  
              // Determine the Group this item belongs in.
              if ($metric instanceof \Closure) {
                  $group = $metric($item);
              } else {
                  $group = $this->getValue($item, $metric);
              }
  
              if (is_numeric($group)) {
                  $group = $metric.$group;
              }
  
              // Check if this group already exists, or else create it.
              if (!isset($GroupedCollection->$group)) {
                  $GroupedCollection->$group = new self();
              }
              $GroupedCollection->$group->add($item);
          }
          return $GroupedCollection;
      }
docs: groupBy
  
  @param callback A callable function.
  @return A collection