scala / scala-library-next

backwards-binary-compatible Scala standard library additions
Apache License 2.0
67 stars 17 forks source link

Unintuitive combinations should be intuitivized #117

Open som-snytt opened 2 years ago

som-snytt commented 2 years ago

Maybe there is a naming convention to indicate a preference for:

or perhaps a context representing the preference.

OndrejSpanel commented 2 years ago

I am not sure which of those three would that be be, perhaps filter, but my expectation is "combinations" is like if working on the sequence indices, creating a combination of them (they are unique, therefore this is well defined, with no surprises) and then using the indices combination to pick the elements from the original collection.

My background (to see where my expectations come from): long time programmer, significant mathematical background, no experience with Python, no experience with functional languages other then Scala.

One-liner implementation for Seq which I think does what I would find intuitive (only not returning a proper String for String):

def myCombinations[T](s: Seq[T], n: Int) = s.indices.combinations(n).map(_.map(s))