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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:02:59+00:00 2026-05-29T06:02:59+00:00

As I understand, method filterKeys of MapLike creates a wrapper over the original map.

  • 0

As I understand, method filterKeys of MapLike creates a wrapper over the original map. So, if I execute the code below m will be a chain of 10K wrappers and the original map.

var m = Map(1 -> "one", 2 -> "two")
for(1 <- 0 until 10000) {m = m.filterKeys(_%2 == 0)}

Now I thought that an invocation of m.contains caused a stack overflow but it does not happen. Could you explain what is going on in this case?

  • 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-29T06:03:00+00:00Added an answer on May 29, 2026 at 6:03 am

    Your loop only executes 1 time, if I copy verbatim. Because of this you are only creating a single wrapper, so what was intended to be a chain of 10000 wrappers is just a chain of 1. It might be a typo, but the loop,

    for(1 <- 0 until 10000) {m = m.filterKeys(_%2 == 0)}
    

    should probably be

    for(i <- 0 until 10000) {m = m.filterKeys(_%2 == 0)}
    

    Aside from that, Daniel is right; fitlerKeys does produce what is essentially a wrapper. It took me more than 10k iterations, but I did manage to create a StackOverflowError.

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

Sidebar

Related Questions

I just wanted to understand if my method has some code that shows an
Howdy, I am trying to understand this method signature: public <K> Map<K, String> getMulti(Serializer<K>
i am wondering if the below code is valid as there is no method
Please help me to understand below code. This is the script for drag and
I'm trying to understand a method using the disassembly feature of Reflector. As anyone
I understand overriding a method/function redefines its implementation in the derived class from its
I understand that static method inheritance is not supported in C#. I have also
I don't understand why one method would work and the other would throw a
I understand that .NET FileStream's Flush method only writes the current buffer to disk,
I understand how to declaratively assign a method to be called when an Image

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.