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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:35:53+00:00 2026-06-15T21:35:53+00:00

What is the most elegant way to vectorize a scala function that returns multiple

  • 0

What is the most elegant way to vectorize a scala function that returns multiple values?

For example, suppose I have the function:

def Foobar(foo: Int, bar: Int): (Int, Int) = (foo, bar)

If it returned a single value, I would do something like this:

val a = Array(1, 2, 3)
val b = Array(4, 5, 6)
val c = (a,b).zipped.map(foobar)

But since it returns a tuple, I end up with an Array[(Int,Int)], whereas I would prefer an (Array[Int], Array[Int]). What is the proper way to do something like this? Are there any clever patterns for generalizing this to something like this:

val c = vectorized(foobar,a,b)

Any ideas would be much appreciated. Thanks!

  • 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-15T21:35:55+00:00Added an answer on June 15, 2026 at 9:35 pm

    You can unzip it (obviously, it operation which is oposite to zip):

    val c = foobar(a,b).unzip
    //res2: (s.c.m.IndexedSeq[Int], s.c.m.IndexedSeq[Int]) = (ArrayBuffer(1, 2, 3),ArrayBuffer(4, 5, 6))
    

    But you’ll end up with IndexedSeqs, not Arrays.

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

Sidebar

Related Questions

What is the most elegant way to implement this function: ArrayList generatePrimes(int n) This
I'm looking for the most elegant way to count the same number values in
What is the most elegant way to turn a hash inside out? By that
What is the shortest / most elegant way to implement the following Scala code
I have N values (integer). I'd like to know what is the most elegant
I'm wondering what is the most elegant way to handle exceptions that depend on
Do you have any insights into the most elegant way of persisting objects from
What is the most elegant way to copy keys and values from one hashtable
What is the most elegant way to achieve something like that with divs for
What is the easiest/most elegant way to do the following in python: def piecewiseProperty(aList):

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.