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

  • Home
  • SEARCH
  • 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 830625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:04:27+00:00 2026-05-15T04:04:27+00:00

When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection

  • 0

When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection with array-like performance characteristics, such as efficient random access):

scala> val s = for (i <- 0 to 9) yield math.random + i
s: scala.collection.immutable.IndexedSeq[Double] = Vector(0.6127056766832756, 1.7137598183155291, ...

Does a for with a yield always return an IndexedSeq, or can it also return some other type of collection class (a LinearSeq, for example)? If it can also return something else, then what determines the return type, and how can I influence it?

I’m using Scala 2.8.0.RC3.

  • 1 1 Answer
  • 1 View
  • 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-15T04:04:28+00:00Added an answer on May 15, 2026 at 4:04 am

    Thanks michael.kebe for your comment.

    This explains how for is translated to operations with map, flatMap, filter and foreach. So my example:

    val s = for (i <- 0 to 9) yield math.random + i
    

    is translated to something like this (I’m not sure if it’s translated to map or flatMap in this case):

    val s = (0 to 9) map { math.random + _ }
    

    The result type of operations like map on collections depends on the collection you call it on. The type of 0 to 9 is a Range.Inclusive:

    scala> val d = 0 to 9
    d: scala.collection.immutable.Range.Inclusive with scala.collection.immutable.Range.ByOne = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    

    The result of the map operation on that is an IndexedSeq (because of the builder stuff inside the collections library).

    So, to answer my question: the result of a for (...) yield ... depends on what type is inside the parantheses. If I want a List as the result, I could do this:

    scala> val s = for (i <- List.range(0, 9)) yield math.random + i
    s: List[Double] = List(0.05778968639862214, 1.6758775042995566, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here are a few thoughts. If you are impatient, skip… May 16, 2026 at 9:58 am
  • Editorial Team
    Editorial Team added an answer You could also take a look at fbgraph. It uses… May 16, 2026 at 9:58 am
  • Editorial Team
    Editorial Team added an answer WPF does not use Win32 handles for individual controls like… May 16, 2026 at 9:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

In Scala, is there a way to get the currently evaluated items in a
scala Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_20). Type in
I'm finding the scala '-i' command line option quite useful for running some scala
I almost always have a Scala REPL session or two open, which makes it
I am unable to evaluate 'modern Perl' code inside the Perl debugger. It works
Following Rick Strahl's example we evaluate javascript on the server. Now I want to
I have a heap of unit tests that need to check XML outputs. I
I'm evaluating Microsoft Team Foundation Server for my customer, who currently uses Visual SourceSafe
I saw lots of presentations on OSGi and i think it sounds promising for
What is the MATLAB-way to check if a vector only contains zeros, so that

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.