original_string: public function sortBy($criteria)
      {
          $criteria = $this->factoryCallableCriteria($criteria);
          $sorted   = $this->create();
          $groups   = $this->groupBy($criteria);
  
          $criterias = $this->map(function ($element, $key) use ($criteria) {
              return $criteria($element, $key);
          })->toArray();
  
          sort($criterias);
          $criterias = array_unique($criterias);
  
          foreach ($criterias as $key) {
              foreach ($groups[$key] as $element) {
                  $sorted[] = $element;
              }
          }
  
          return $sorted;
      }
code: public function sortBy($criteria)
      {
          $criteria = $this->factoryCallableCriteria($criteria);
          $sorted   = $this->create();
          $groups   = $this->groupBy($criteria);
  
          $criterias = $this->map(function ($element, $key) use ($criteria) {
              return $criteria($element, $key);
          })->toArray();
  
          sort($criterias);
          $criterias = array_unique($criterias);
  
          foreach ($criterias as $key) {
              foreach ($groups[$key] as $element) {
                  $sorted[] = $element;
              }
          }
  
          return $sorted;
      }
code_tokens: public function sortBy ( $ criteria ) { $ criteria = $ this -> factoryCallableCriteria ( $ criteria ) ; $ sorted = $ this -> create ( ) ; $ groups = $ this -> groupBy ( $ criteria ) ; $ criterias = $ this -> map ( function ( $ element , $ key ) use ( $ criteria ) { return $ criteria ( $ element , $ key ) ; } ) -> toArray ( ) ; sort ( $ criterias ) ; $ criterias = array_unique ( $ criterias ) ; foreach ( $ criterias as $ key ) { foreach ( $ groups [ $ key ] as $ element ) { $ sorted [ ] = $ element ; } } return $ sorted ; }
docstring: Sort elements by the given criteria
  
  @param mixed $criteria it can be either a callable function or a string,
  representing a key of an element
  
  @return Hash
docstring_tokens: Sort elements by the given criteria