Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintuitive combinations should be intuitivized #117

Open
som-snytt opened this issue Feb 25, 2022 · 1 comment
Open

Unintuitive combinations should be intuitivized #117

som-snytt opened this issue Feb 25, 2022 · 1 comment

Comments

@som-snytt
Copy link

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

  • status quo (arbitrary sequences)
  • multiset result
  • filter of current sequence (so if I want 2x, 1y, "xyx" yields "xyx" not "xxy")

or perhaps a context representing the preference.

@OndrejSpanel
Copy link
Member

OndrejSpanel commented Feb 25, 2022

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants