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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:02:14+00:00 2026-05-22T18:02:14+00:00

When one has an array of objects it is often desirable (e.g. for performance

  • 0

When one has an array of objects it is often desirable (e.g. for performance reasons) to update (replace) some of the objects in place. For example, if you have an array of integers, you might want to replace the negative integers with positive ones:

// Faster for primitives
var i = 0
while (i < a.length) {
  if (a(i) < 0) a(i) = -a(i)
  i += 1
}

// Fine for objects, often okay for primitives
for (i <- a.indices) if (a(i) < 0) a(i) = -a(i)

What is the canonical way to perform a modification like this using the parallel collections library?

  • 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-22T18:02:15+00:00Added an answer on May 22, 2026 at 6:02 pm

    As far as parallel arrays are considered – it’s an oversight. A parallel transform for parallel arrays will probably be included in the next release.

    You can, however, do it using a parallel range:

    for (i <- (0 until a.length).par) a(i) = computeSomething(i)
    

    Note that not all mutable collections are modifiable in place this way. In general, if you wish to modify something in place, you have to make sure it’s properly synchronized. This is not a problem for arrays in this case, since different indices will modify different array elements (and the changes are visible to the caller at the end, since the completion of a parallel operation guarantees that all writes become visible to the caller).

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

Sidebar

Related Questions

I have an array of object names. These objects are HTML elements. I want
I have an array of objects: Object = { 1 : { name :
I'm using an array $timeslotlist that contains multiple timeslot objects. Each timeslot has multiple
Suppose that you're given an array A of n distinct elements drawn from some
I have been debugging my app and checking the memory allocation and came across,
This piece of code iterates over a tree of TreeNode objects where every object
In my iPhone development book, I'm seeing some strange coding examples in regard to
I need some advice, because I am new to c++ For my wind turbine
Possible Duplicate: Chained Hash Tables vs. Open-Addressed Hash Tables In general I have seen
I'm still new to OOP, and the way I initially perceived it was to

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.