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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:27:31+00:00 2026-05-25T15:27:31+00:00

I have a 2d array of type boolean (not important) It is easy to

  • 0

I have a 2d array of type boolean (not important)
It is easy to iterate over the array in non-functional style.
How to do it FP style?

var matrix = Array.ofDim[Boolean](5, 5) 

for ex, I would like to iterate through all the rows for a given column and return a list of int that would match a specific function.
Example: for column 3, iterate through rows 1 to 5 to return 4, 5 if the cell at (4, 3), (5, 3) match a specif function. Thx v much

def getChildren(nodeId: Int) : List[Int] = {
    info("getChildren("+nodeId+")")

    var list = List[Int]()
    val nodeIndex = id2indexMap(nodeId)

    for (rowIndex <- 0 until matrix.size) {
      val elem = matrix(rowIndex)(nodeIndex)
      if (elem) {
        println("Row Index = " + rowIndex)
        list = rowIndex :: list
      }
    }

    list
  }
  • 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-25T15:27:32+00:00Added an answer on May 25, 2026 at 3:27 pm

    What about

    (1 to 5) filter {i => predicate(matrix(i)(3))}
    

    where predicate is your function?

    Note that initialized with (5,5) indexes goes from 0 to 4.

    Update: based on your example

    def getChildren(nodeId: Int) : List[Int] = {
      info("getChildren("+nodeId+")")
      val nodeIndex = id2indexMap(nodeId)
    
      val result = (0  until matrix.size).filter(matrix(_)(nodeIndex)).toList
      result.forEach(println)
      result
    }
    

    You may move the print in the fiter if you want too, and reverse the list if you want it exactly as in your example

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

Sidebar

Related Questions

I have a matrix in the type of a Numpy array. How would I
I have an array of an anonymous type declared as: var list = new[]
I have a NumPy array 'boolarr' of boolean type. I want to count the
Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username',
I have an array of different type objects and I use a BinaryWriter to
I have an array of any type T ( T[] ) and I want
I have an array of a certain type. Now I want to find an
I'm looking for a kind of array data-type that can easily have items added,
I have a object (product), with a property of type 'array' e.g. product.tags =
Ok, I have an array like so: $myArray[32]['value'] = 'value1'; $myArray[32]['type'] = 'type1'; $myArray[33]['value']

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.