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

  • Home
  • SEARCH
  • 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 7617895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:15:37+00:00 2026-05-31T03:15:37+00:00

I am trying to zip multiple sequences to form a long tuple: val ints

  • 0

I am trying to zip multiple sequences to form a long tuple:

val ints = List(1,2,3)
val chars = List('a', 'b', 'c')
val strings = List("Alpha", "Beta", "Gamma")
val bools = List(true, false, false)

ints zip chars zip strings zip bools

What I get:

List[(((Int, Char), String), Boolean)] =
  List((((1,a),Alpha),true), (((2,b),Beta),false), (((3,c),Gamma),false))

However I would like to get a sequence of flat tuples:

List[(Int, Char, String, Boolean)] = 
  List((1,a,Alpha,true), (2,b,Beta,false), (3,c,Gamma,false))

I now I can do:

List(ints, chars, strings, bools).transpose

But it returns weakly typed List[List[Any]]. Also I can do (ints, chars, strings).zipped, but zipped works only on 2-tuples and 3-tuples.

Is there a way to zip (arbitrary) number of equal-length sequences easily?

  • 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-31T03:15:38+00:00Added an answer on May 31, 2026 at 3:15 am

    Here’s one way to solve your example, but this is not for an arbitrary number of sequences.

    val ints = List(1,2,3)
    val chars = List('a', 'b', 'c')
    val strings = List("Alpha", "Beta", "Gamma")
    val bools = List(true, false, false)
    
    val input = ints zip chars zip strings zip bools
    
    // Flattens a tuple ((A,B),C) into (A,B,C)
    def f2[A,B,C](t: ((A,B),C)) = (t._1._1, t._1._2, t._2)
    
    // Flattens a tuple ((A,B),C,D) into (A,B,C,D)
    def f3[A,B,C,D](t: ((A,B),C,D)) = (t._1._1, t._1._2, t._2, t._3)
    
    input map f2 map f3
    

    I don’t think it is possible to do it generically for tuples of arbitrary length, at least not with this kind of solution. Tuples are strongly-typed, and the type system doesn’t allow you to specify a variable number of type parameters, as far as I know, which makes it impossible to make a generalized version of f2 and f3 that takes a tuple of arbitrary length ((A,B),C,D,...) (that would return a tuple (A,B,C,D,...)).

    If there were a way to specify a variable number of type parameters, we wouldn’t need traits Tuple1, Tuple2, … Tuple22 in Scala’s standard library.

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

Sidebar

Related Questions

I am trying to zip a long string into a file and to retrieve
I am trying to download multiple PDF files as one zip file and then
We're trying to build up a minorly complicated Zip file in Gradle from multiple
I am trying to compress multiple files into a single zip archive and I
I'm trying to search multiple fields (zc_city, zc_zip and zc_state), matching against a single
I am trying to zip files to an SQL Server database table. I can't
I am developing an iOS application, and trying to zip the file I have
I'm trying to create a Zip file from .Net that can be read from
I'm trying to find an zip compression and encryption component with encryption suitable for
I am trying to organize a Zip Archive into an array so that I

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.