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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:11:48+00:00 2026-06-13T06:11:48+00:00

I hope it is okay if I post solved problems and ask for a

  • 0

I hope it is okay if I post solved problems and ask for a more beautiful solution, so that I can see how it is done correctly

I wanted a list of all process names mapped with a ProcessID. Something like "notepad.exe" -> 4242
Ofc there can be multiple instances so it should be something like "notepad.exe" -> List(4242,7171)

I have a method which gives me a tuple

private def extractProcess(s: String): (String, Int) = {
    val process = s.split(" ").filterNot(str => str == "")
    (process(0), process(1).toInt)
}

output would be ("Notepad.exe",4242)

processList containt the raw string from windows tasklist which looks something like this

svchost.exe                   4464 Services                   0        47.656 K

Now I want to create a map with all processes and I have done it like this

val process: Map[String, List[Int]] = Map()
    processList.drop(5).map(s => {
      val element = extractProcess(s)
      if (process contains element._1) {
        val p = process get element._1
        process(element._1) = p.get ::: List(element._2)
      } else {
        process(element._1) = List(element._2)
      }
    })

I droped the first 5 elements because they are not needed

Now the output would look like this

...
(tasklist.exe,List(5036))
(NLClientApp.exe,List(2812))
(wininit.exe,List(444))
(SearchFilterHost.exe,List(5476))
(svchost.exe,List(656, 732, 928, 964, 992, 1036, 1140, 1360, 2168, 4464, 4764, 5048))
...

Which is what I wanted to do.
Are there better ways of creating the map?

I always think more imperative than functional, it is hard to think different.

  • 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-13T06:11:49+00:00Added an answer on June 13, 2026 at 6:11 am

    Could be made simpler like this:

    processList.drop(5).map(extractProcess).groupBy(_._1).mapValues(_.map(_._2))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this is okay to ask here as its more a request for
Okay, I have a problem that I hope you can help me fix. I
Hope that someone can share their experience with some of the latest emerging backbone.js
Hope the AWK gurus can provide a solution to my problem . I have
Okay, I'm hating Javascript right now, and I hope someone can help me. I
I hope I can word this okay. I have multiple divs all called '.collapse-conten'
Okay, in my head this is somewhat complicated and I hope I can explain
I hope its okay I ask this, I searched around stackoverflow and found similair
Hope you're having a good Friday and stuff... okay, so here's my question: All
hope someone can answer this. Here is some sample code. namespace std { #ifdef

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.