@@ 537-553 (lines=17) @@ | ||
534 | * |
|
535 | * @return Map |
|
536 | */ |
|
537 | public function sort(callable $comparator = null): Map |
|
538 | { |
|
539 | $sorted = $this->copy(); |
|
540 | ||
541 | if ($comparator) { |
|
542 | usort($sorted->pairs, function($a, $b) use ($comparator) { |
|
543 | return $comparator($a->value, $b->value); |
|
544 | }); |
|
545 | ||
546 | } else { |
|
547 | usort($sorted->pairs, function($a, $b) { |
|
548 | return $a->value <=> $b->value; |
|
549 | }); |
|
550 | } |
|
551 | ||
552 | return $sorted; |
|
553 | } |
|
554 | ||
555 | /** |
|
556 | * Returns a sorted copy of the map, based on an optional callable |
|
@@ 563-579 (lines=17) @@ | ||
560 | * |
|
561 | * @return Map |
|
562 | */ |
|
563 | public function ksort(callable $comparator = null): Map |
|
564 | { |
|
565 | $sorted = $this->copy(); |
|
566 | ||
567 | if ($comparator) { |
|
568 | usort($sorted->pairs, function($a, $b) use ($comparator) { |
|
569 | return $comparator($a->key, $b->key); |
|
570 | }); |
|
571 | ||
572 | } else { |
|
573 | usort($sorted->pairs, function($a, $b) { |
|
574 | return $a->key <=> $b->key; |
|
575 | }); |
|
576 | } |
|
577 | ||
578 | return $sorted; |
|
579 | } |
|
580 | ||
581 | /** |
|
582 | * @inheritDoc |