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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:18:40+00:00 2026-06-13T01:18:40+00:00

If two expressions e1 and e2 only deal with immutable data structures, then evaluating

  • 0

If two expressions e1 and e2 only deal with immutable data structures, then evaluating the tuple (e1, e2) in parallel should be dead simple, just evaluate the two expressions on different processors and don’t worry about any interactions, because there shouldn’t be any.

Scala has lots of immutable data structures, so I would expect there to be a super simple (to write) way of evaluating that tuple in parallel. Something like

par_tuple : ( Unit -> T1) -> (Unit -> T2) -> (T1, t2)

which evaluates the two functions in parallel and returns when both have finished.

I haven’t seen it yet, though. Does it exist? If not how would you write it?

  • 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-13T01:18:41+00:00Added an answer on June 13, 2026 at 1:18 am

    It depends how costly is the expression being evaluated is. On current architectures, two expressions involving few to dozens, even hundreds of instructions cannot be evaluated in parallel efficiently. So you should always make sure that the amount of work you’re executing isn’t shadowed by the cost of parallelization itself.

    With this disclaimer in mind, in Scala 2.10 you can use Futures to accomplish this:

    val f = future { e1 }
    val g = future { e2 }
    (Await.result(f), Await.result(g))
    

    Note that this style of computations is discouraged (and the above is deliberately overly verbose!), because it involves blocking, and blocking on platform such as the JVM, where there is no concept of efficient continuations, is often costly (though the situations where it is applicable is beyond the scope of this answer, and probably of this answerer). In most cases you should install a callback on the future which is called once its value becomes available. You can do this instead:

    val h = for {
      x <- f
      y <- g
    } yield (x, y)
    

    where h above is a new future which will contain a tuple of values once both become available.

    You could rewrite your function par_tuple to either:

    def par_tuple[E1, E2](e1: =>E1, e2: =>E2): Future[(E1, E2)] = {
      val f = future { e1 }
      val g = future { e2 }
      val h: Future[(E1, E2)] = for {
        x <- f
        y <- g
      } yield (x, y)
      h
    }
    

    This method returns a Future of the tuple you want – an object which will eventually hold the tuple with your expressions. You can compose this future further with other computations, or if you’re sure you want to block, you can have another variant:

    def par_tuple_blocking[E1, E2](e1: =>E1, e2: =>E2): (E1, E2) = Await.result(par_tuple(e1, e2))
    

    which blocks until the tuple becomes available in the future.

    See more about futures, callbacks and blocking here.

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

Sidebar

Related Questions

I need two regular expressions to identify if .. then .. else .. endif
I'm wondering if these two expressions are equivalent, because if they are, it would
I have two regular expressions: /\/(\w\w+)/g /(^\w\w+)/g and am wondering if there's any way
I'm trying to craft two regular expressions that will match URIs. These URIs are
How would I go about joining two lambda expressions like theese: Expression<Func<string, bool>> expr1
I am trying to get all logfiles between two dates with regular expressions. My
I want to use Expression.Add to sum two data types, which might be a
I'm using two regular expressions to pull assignments out of MySQL queries and using
I'm studying Regular Expressions by reading Aho's book. I don't understand two of the
I have two regular expressions that I use to validate Colorado driver's license formats.

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.