Skip to content

Stream::sortBy дублирует элементы при совпадении значения #30

@garr1nch4

Description

@garr1nch4
class Item {

    private $value;

    public function __construct($value) {
        $this->value = $value;
    }

    public function getValue() {
        return $this->value;
    }

}

$items = [
    new Item(1),
    new Item(7),
    new Item(7),
];
$res = \WS\Utils\Collections\CollectionFactory::from($items)
    ->stream()
    ->map(function ($a) {
        return $a;
    })
    ->sortBy(function(Item $item) {
        return $item->getValue();
    })
    ->getCollection()
;

echo $res->size();

Output:

5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions