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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:09:46+00:00 2026-05-22T03:09:46+00:00

trying to run the sample code in the Apress book called Beginning Scala. I

  • 0

trying to run the sample code in the Apress book called “Beginning Scala”. I even downloaded the code from their website to make sure I didn’t goof. Getting the following message:

/root/sum.scala:19: error: missing arguments for method collect in trait Iterator;
follow this method with `_' if you want to treat it as a partially applied function
val lines = input.getLines.collect 
                           ^
one error found

and here is the source code i used (running Scala version 2.8.1.final (Java HotSpot(TM) Server VM, Java 1.6.0_22 on Fedora 13)

import scala.io._

def toInt(in: String): Option[Int] =
  try {
    Some(Integer.parseInt(in.trim))
  } catch {
    case e: NumberFormatException => None
  }

def sum(in: Seq[String]) = {
  val ints = in.flatMap(s => toInt(s))
  ints.foldLeft(0)((a, b) => a + b)
}

println("Enter some numbers and press ctrl-D (Unix/Mac) ctrl-C (Windows)")

val input = Source.fromInputStream(System.in)

val lines = input.getLines.collect

println("Sum "+sum(lines))

looks like this is the relevant change:

The Iterator.collect() method in 2.7.7 returns a Seq. In 2.8, it is used to perform a conditional map using a PartialFunction. You can use input.getLines.toSeq instead.

  • 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-22T03:09:47+00:00Added an answer on May 22, 2026 at 3:09 am

    Ah, I remember this:

    EDIT: replaced with more in depth answer

    The code was written against Scala
    2.7.3 and 2.8 introduces some breaking changes.

    Here’s an update to the code that
    works under Scala 2.8.0:

    import scala.io._
    
    object Sum {
      def main(args: Array[String]): Unit = {
        println("Enter some numbers and press ctrl-D (Unix/Mac) ctrl-Z (Windows)")
        val input = Source.fromInputStream(System.in)
        val lines = input.getLines.toList
        println("Sum " + sum(lines))
      }
    
      def toInt(s: String): Option[Int] = {
        try {
          Some(Integer.parseInt(s))
        } catch {
            case e: NumberFormatException => None
        }
      }
    
      def sum(in: Seq[String]): Int = {
        val ints = in.flatMap(toInt(_))
        ints.foldLeft(0)((a, b) => a + b)
      }
    
    }
    

    Source: http://scala-programming-language.1934581.n4.nabble.com/Beginning-Scala-book-problem-td2966867.html

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

Sidebar

Related Questions

I have downloaded TableView sample code '4_TableViewCellSubviews' from internet. I am trying to run
When trying to run the sample code here: http://www.nikhilk.net/Live-Search-REST-API.aspx I get: Error 52 The
I am trying to run the sample code for tftp server. I get no
I am newbie with JPA. I'm trying to run some sample code using JPA
I'm trying to run a batch file, as another user, from my web app.
I'm trying to run SQuirreL SQL. I've downloaded it and installed it, but when
I'm trying to run sample Perl script on Windows 7 and I configured IIS
I downloaded the latest video capture samples from WWDC 2010 and am trying to
I'm trying to run a c++ 2d array (pretty simple file) and it works
I am trying to run the VS 2008 SP1 installer , but it says

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.