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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:06:27+00:00 2026-06-13T20:06:27+00:00

Following Scala courses on Coursera, Martin Odersky showed an example code which is: 1

  • 0

Following Scala courses on Coursera, Martin Odersky showed an example code which is:

1 to 5 map ( i => i*i )

And he said the Range gets transformed to a Vector because they share the same interface (IndexedSeq) and the result could not be represented as a Range
(it was more clear in its example since he generated a pair which is not representable as a Range).

I’m not sure to understand because I think he said previously that in a for expression the 1st generator will determine the kind of element that will be yielded, and it seems not always true, at least for Range.

And I’m not sure to understand why the output is Vector, because Vector may not be the only other one implementation that can represent the result computed above.

Can someone help me understand this part please?

  • 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-13T20:06:28+00:00Added an answer on June 13, 2026 at 8:06 pm

    map secretly takes a CanBuildFrom as an implicit argument. Its job is to produce a new collection given the one you’ve already got (and the type of the contents). Since Range can’t contain arbitrary stuff–not even arbitrary integers–there is no CanBuildFrom that produces a Range. The most specific supertype of Range that does have a CanBuildFrom is IndexedSeq. The collection that is actually built by this is a Vector.

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

Sidebar

Related Questions

From the Scala API , I got the following example, which does not compile;
I have the following Scala code: class X[T1 <: AnyRef] { var _x :
I'm running the following Scala code. It compiles a single display list of 10,000
In Scala IDE I have the following code: package pkg.one object S { class
I have the following scala code: package dummy import javax.servlet.http.{HttpServlet, HttpServletRequest => HSReq, HttpServletResponse
Suppose I have the following Scala code: class Foo(a: Int) class Bar(b: Buffer[Int]) extends
What is the shortest / most elegant way to implement the following Scala code
I'm following the Scala course on Coursera. I've started to read the Scala book
The following Scala code fails to compile in Scala 2.7.7, with a type mismatch
I have the following Scala code. import scala.actors.Actor object Alice extends Actor { this.start

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.