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 6667977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:59:25+00:00 2026-05-26T02:59:25+00:00

I want following function range((1,1), (2,2)) which return Seq[(Int,Int)]((1,1),(1,2),(2,1),(2,2)) It is analog for one

  • 0

I want following function
range((1,1), (2,2)) which return

Seq[(Int,Int)]((1,1),(1,2),(2,1),(2,2))

It is analog for one dimensional range with 1 to 2

The function should work for any scala tuple (i.e. Tuple2, Tuple3, Tuple4, …) and be typesafe.

I’ve tried with

    def tupleRange[T <: Product](t1:T, t2:T):Seq[T] = {
        assert(t1.productArity == t2.productArity)
        def tail(t:Product):Product = sys.error("todo"); 
        def join(i:Int, p:Product):T = sys.error("todo");
        for(
v <- t1.productElement(0).asInstanceOf[Int] to t2.productElement(0).asInstanceOf[Int]; 
v2 <- tupleRange(tail(t1), tail(t2)))
            yield join(v,v2)
    }
    implicit def range[T <:Product](p1:T) = new { def to(p2:T) = tupleRange(p1,p2)}

But I think I’ve chosen wrong direction.

  • 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-05-26T02:59:25+00:00Added an answer on May 26, 2026 at 2:59 am

    I’d suggest the same thing that @ziggystar suggested above. Use List[Int] instead of tuples of Ints.

    scala> import scalaz._
    import scalaz._
    
    scala> import Scalaz._
    import Scalaz._
    
    scala> def range(xs: List[Int], ys: List[Int]): List[List[Int]] = {
         |   (xs, ys).zipped.map((x, y) => List.range(x, y + 1)).sequence
         | }
    range: (xs: List[Int], ys: List[Int])List[List[Int]]
    
    scala> range(List(1, 2, 4), List(2, 5, 6))
    res29: List[List[Int]] = List(List(1, 2, 4), List(1, 2, 5), List(1, 2, 6), 
    List(1, 3, 4), List(1, 3, 5), List(1, 3, 6), List(1, 4, 4), List(1, 4, 5), 
    List(1, 4, 6), List(1, 5, 4), List(1, 5, 5), List(1, 5, 6), List(2, 2, 4), 
    List(2, 2, 5), List(2, 2, 6), List(2, 3, 4), List(2, 3, 5), List(2, 3, 6), 
    List(2, 4, 4), List(2, 4, 5), List(2, 4, 6), List(2, 5, 4), List(2, 5, 5), 
    List(2, 5, 6))
    

    This implementation assumes that xs and ys are ordered and have same length.

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

Sidebar

Related Questions

I have the following function, which generates an integer in a given range: 18
Look at the following Python code: def function(x): return x, x+1 sequence = range(5)
I want to define a following function: if(stmtToFinalize) { NSLog(@Finalizing statement stmtToFinalize); if (sqlite3_finalize(stmtToFinalize)
Consider the following function: void f(const char* str); Suppose I want to generate a
I want to define a constant in objective-c. Previously I had the following function:
I want to write the following procedure / function: procedure ShowSysPopup(aFile: string; x, y:
Ideally I want a function something like the following (this example doesn't compile): void
I want to be able to parse the following times using ParseExact() function: 01:02:03
I want to do the equivalent of the following VB in c# Function([class]) hello
I want to call the Sleep function on ASM. So I wrote the following:

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.