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

Collection-like operations on tuples #199

Open
OndrejSpanel opened this issue Jan 20, 2023 · 3 comments
Open

Collection-like operations on tuples #199

OndrejSpanel opened this issue Jan 20, 2023 · 3 comments

Comments

@OndrejSpanel
Copy link
Member

OndrejSpanel commented Jan 20, 2023

Sometimes I work with homogenous tuples, which I use more like a collection with a fixed size. When working in this style, I often define a map extension for tuples. Would something like this be worth adding here?

Example:

  implicit class AnyTuple2Ops[T](v: (T, T)) {
    def map[X](f: T => X): (X, X) = (f(v._1), f(v._2))
  }

  implicit class AnyTuple3Ops[T](v: (T, T, T)) {
    def map[X](f: T => X): (X, X, X) = (f(v._1), f(v._2), f(v._3))
  }

  implicit class AnyTuple4Ops[T](v: (T, T, T, T)) {
    def map[X](f: T => X): (X, X, X, X) = (f(v._1), f(v._2), f(v._3), f(v._4))
  }

Other operations in similar style can be added, like:

  implicit class AnyTuple2Ops[T](v: (T, T)) {
    def combine(that: (T, T))(by: (T, T) => T): (T, T) = (by(v._1, that._1), by(v._2, that._2))
  }
@SethTisue
Copy link
Member

Would it impair the usability of the library on Scala 3?

@OndrejSpanel
Copy link
Member Author

I am not sure I understand the question. Do you mean you expect some interference with Scala 3, such that the library would be unusable on some Scala 3 projects because of these tuple operations added?

@SethTisue
Copy link
Member

SethTisue commented Mar 7, 2023

I'm asking because Scala 3 has its own map method on Tuple, taking a polymorphic function.

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