orderBy() 공개 메소드

Orders the values mapped from the supplied function according the supplied direction.
public orderBy ( callable $function, integer $direction ) : Pinq\Interfaces\IOrderedTraversable
$function callable The projection function
$direction integer
리턴 Pinq\Interfaces\IOrderedTraversable
예제 #1
0
 public function visitOrderBy(Segments\OrderBy $query)
 {
     $first = true;
     foreach ($query->getOrderings() as $orderFunction) {
         $direction = $this->resolvedParameters[$orderFunction->getIsAscendingId()] ? Direction::ASCENDING : Direction::DESCENDING;
         if ($first) {
             $this->traversable = $this->traversable->orderBy($this->resolvedParameters[$orderFunction->getProjectionFunction()->getCallableId()], $direction);
             $first = false;
         } else {
             $this->traversable = $this->traversable->thenBy($this->resolvedParameters[$orderFunction->getProjectionFunction()->getCallableId()], $direction);
         }
     }
 }
예제 #2
0
 /**
  * @dataProvider names
  */
 public function testThatOrderByDescendingIsEquivalentToOrderByWithDescendingDirection(\Pinq\ITraversable $names, array $data)
 {
     $function = function ($i) {
         return $i[0];
     };
     $orderedNames = $names->orderByDescending($function);
     $otherOrderedNames = $names->orderBy($function, \Pinq\Direction::DESCENDING);
     $this->assertSame($orderedNames->asArray(), $otherOrderedNames->asArray());
 }