Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala SeqLike distinct preserves order?

Tags:

scala

The apidoc of distinct in SeqLike says:

Builds a new sequence from this sequence without any duplicate elements. Returns: A new sequence which contains the first occurrence of every element of this sequence.

Do I feel it correct that no ordering guarantee is provided? More generally, do methods of SeqLike provide any process-in-order (and return-in-order) guarantee?

like image 811
ron Avatar asked Jul 18 '11 15:07

ron


2 Answers

On the contrary: operations on Seqs guarantee the output order (unless the API says otherwise). This is one of the basic properties of sequences, where the order matters, versus sets, where only containment matters.

like image 196
Jean-Philippe Pellet Avatar answered Sep 27 '22 22:09

Jean-Philippe Pellet


It depends on the collection you were using in the first place. If you had a list you'll get your order. If on the other hand you had a set, then probably not.

like image 20
agilesteel Avatar answered Sep 27 '22 22:09

agilesteel