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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:10:20+00:00 2026-05-23T23:10:20+00:00

Specifically I’m looking at Problem 1 here http://pavelfatin.com/scala-for-project-euler/ The code as listed is as

  • 0

Specifically I’m looking at Problem 1 here

http://pavelfatin.com/scala-for-project-euler/

The code as listed is as follows

val r = (1 until 1000).view.filter(n => n % 3 == 0 || n % 5 == 0).sum

I can follow everything except for “view”. In fact if I take out view the code still compiles and produces exactly the same answer.

  • 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-23T23:10:21+00:00Added an answer on May 23, 2026 at 11:10 pm

    View produces a lazy collection, so that calls to e.g. filter do not evaluate every element of the collection. Elements are only evaluated once they are explicitly accessed. Now sum does access all elements, but with view the call to filter doesn’t create a full Vector. (See comment by Steve)

    A good example of the use of view would be:

    scala> (1 to 1000000000).filter(_ % 2 == 0).take(10).toList
    java.lang.OutOfMemoryError: GC overhead limit exceeded
    

    Here Scala tries to create a collection with 1000000000 elements to then access the first 10. But with view:

    scala> (1 to 1000000000).view.filter(_ % 2 == 0).take(10).toList
    res2: List[Int] = List(2, 4, 6, 8, 10, 12, 14, 16, 18, 20)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Specifically I want to make a QR code to http://example.com be the favicon for
Specifically, the concept of set referred to here: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html#%_sec_2.3.3 I understand how the data
Specifically, the code sample here works great, but only when the string is stored
Specifically what I am looking to do is make the icons for the Nodes
Specifically, I am looking to zero pad a number to create a string based
Specifically I have code that simplifies to this: from datetime import datetime date_string =
Specifically, I am talking about this code: $(window).scroll(function(){ var loc = $('html').offset().top; }); To
Specifically looking for 3rd party tools free/commercial that have reduced development time.
Specifically I am looking for a good OOP PHP CURL class that can be
Specifically this is regarding when using a client session cookie to identify a session

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.