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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:39:38+00:00 2026-06-18T08:39:38+00:00

I ma trying to convert the following Scala 2.9 implicit conversion method to a

  • 0

I ma trying to convert the following Scala 2.9 implicit conversion method to a 2.10 implicit class:

import java.sql.ResultSet

/**
 * Implicitly convert a ResultSet to a Stream[ResultSet]. The Stream can then be
 * traversed using the usual map, filter, etc.
 *
 * @param row the Result to convert
 * @return a Stream wrapped around the ResultSet
 */
implicit def stream(row: ResultSet): Stream[ResultSet] = {
  if (row.next) Stream.cons(row, stream(row))
  else {
    row.close()
    Stream.empty
  }
}

My first attempt does not compile:

implicit class ResultSetStream(row: ResultSet) {
  def stream: Stream[ResultSet] = {
    if (row.next) Stream.cons(row, stream(row))
    else {
      row.close()
      Stream.empty
    }
  }
}

I get a syntax error on stream(row) because stream does not take a parameter.

What is the correct way to do this?

  • 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-18T08:39:39+00:00Added an answer on June 18, 2026 at 8:39 am

    Try this :

    scala> import java.sql.ResultSet
    import java.sql.ResultSet
    
    scala> implicit class ResultSetStream(row: ResultSet) {
         |     def stream: Stream[ResultSet] = {
         |       if (row.next) Stream.cons(row, row.stream)
         |       else {
         |         row.close()
         |         Stream.empty
         |       }
         |     }
         |   }
    defined class ResultSetStream
    

    You defined stream as function, so stream(row) can not work.

    You can inherit from AnyVal to create a Value Class and optimize your code:

    implicit class ResultSetStream(val row: ResultSet) extends AnyVal {
        def stream: Stream[ResultSet] = {
          if (row.next) Stream.cons(row, row.stream)
          else {
            row.close()
            Stream.empty
          }
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert the following Java code into Scala: ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin)nnet.getPlugin(ImageRecognitionPlugin.class)
I am trying to convert the following c# code into java abstract class BaseProcessor<T>
I am trying to convert the following Java code snippet into Python. Can someone
I'm trying to convert following java snippet to Xtend, but i couldn't able to
Trying to convert the following but am having difficulty. Can anyone see where I'm
I am trying to convert the following SQL into a LINQ expression SELECT COUNT(ID)
I'm trying to convert the following list into a select list so it can
I'm trying to convert the following javascript to java var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R)
I am trying to convert the following java binary search routine to as3. I
I am trying to convert the following regular expression from Java to .NET: (?i:(?:([^\d,]+?)\W+\b((?:CA|SD|SC|CT|DC)\b)?\W*)?(\d{5}(?:[-

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.