Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:27:41+00:00 2026-06-06T02:27:41+00:00

Given two tuples of the same arity, how can I lexicographically compare them? It

  • 0

Given two tuples of the same arity, how can I lexicographically compare them? It seems like this should be as simple as in the following snippet, but it isn’t. Any simple example of how to do it?

var x = (1,2,3) < (1,2,4)

Were they lists, I could define a recursive function that would compare the lists’ head until a difference or the end of a list was found, but I don’t think I could do that for tuples.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:27:45+00:00Added an answer on June 6, 2026 at 2:27 am

    It’s not simple because while

    var x = (1,2,3) < (1,2)
    

    looks pretty simple,

    var x = (1,false,3) < (1,2)
    

    is not. How do you deal with non-ordered types? How do you deal with different types in the same tuple position?

    Do you mandate all types to be the same? In that case, you do not have a tuple. The whole point of a tuple is that its arity is fixed (you statically know how big it is) and each element can be of a different type.

    If I found myself with that problem — and I’d try very hard not to — I’d grab Shapeless, convert the tuples into something like HLists, and then try to compare on that.

    EDIT

    Ah, now it is much easier:

    import scala.math.Ordering.Implicits._
    var x = (1,2,3) < (1,2,4)
    

    These extra implicits are not automatically available because they can result in diverging implicits under some circumstances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given two resources http://example.com/places/1 http://example.com/places/2 How should the endpoint look like to merge both
This seems like a simple task or a repeat, but bear with me-- I've
Given two strings text1 and text2 : public SOMEUSABLERETURNTYPE Compare(string text1, string text2) {
Given: two images of the same subject matter; the images have the same resolution,
Given two methods on the same class in Java : public void doSomething( Person
Say I create two sets of tuples like so: Dim losSPResults As List(Of spGetDataResults)
What's the most compact way to return the following: Given a list of tuples,
I have two lists of fixed-length tuples. This function calculates a fraction (ratio) for
Given two lists (IList) A and B. I would like to use linq to
Given two identical boost::variant instances a and b , the expression ( a ==

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.