What's the `order` mean in seq.combinations?

see: scala seq.combinations returns out of order results - Stack Overflow

It makes me confused in docs of Seq.combinations it says

Iterates over combinations. A combination of length n is a subsequence of the original sequence, with the elements taken in order. Thus, “xy” and “yy” are both length-2 combinations of “xyy”, but “yx” is not. If there is more than one way to generate the same subsequence, only one will be returned.

And it returns

// should here be List("cb", "cc") ?
scala> "cbc".combinations(2).toList
val res23: List[String] = List(cc, cb)

scala> "cba".combinations(2).toList
val res24: List[String] = List(cb, ca, ba)

Does I misunderstanding order here?

The behavior when the input includes duplicates is underspecified, it seems to me. You’ll probably need to look at the implementation to figure out what happens in that case. A pull request improving the documentation would be welcome.

Thanks your reply, I will try to open a PR later after when I get off work.

1 Like