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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:03:40+00:00 2026-06-03T16:03:40+00:00

I have a case class that has a few parameters for its constructor, and

  • 0

I have a case class that has a few parameters for its constructor, and I define an accompanying class object that defines an alternative constructor that takes a different set of arguments, like so:

case class MyClass (c: Char, mc: List[MyClass]) 

object MyClass {
  def apply(c: Char, mc: MyClass): MyClass = {
    MyClass(c, List(mc))
  }
}

I want to use the original case class constructor in a foldRight:

object SomeStuff {
  def problem (s: String) {
    assert(!s.isEmpty)

    val zero = MyClass('a', Nil)

    val mc2 = "Pillsy Pillsy Pillsy" foldRight(zero) {
      MyClass(_, List(_))
    }
  }
}

When I do this, I get an error message from the compiler: “MyClass does not take parameters.” If I comment out the section val mc2 = ... this problem goes away, but MyClass is clearly taking parameters in the definition of zero. I feel like I must be missing something really basic, but I have no idea what it is. I’ve tried a couple workarounds, like defining a helper method or a function value to use as the second argument of foldRight, but none of it helps, which is not too surprising since I’m basically fumbling around randomly.

  • 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-03T16:03:43+00:00Added an answer on June 3, 2026 at 4:03 pm

    First, foldRight takes two arguments, so you can’t use operator notation (in its current form), but you can:

    ("foo" foldRight zero) { ... }
    

    or alternatively,

    ("foo" :\ zero) { ... }
    

    Second, { MyClass(_, List(_)) } will desugar into

    { x => MyClass(x, y => List(y)) }
    

    so, you should name arguments and use new keyword to ensure that constructor is called instead of apply method:

    "Pillsy Pillsy Pillsy".foldRight(zero) { (c, mc) =>
      new MyClass(c, List(mc))
    }
    

    or use supplemental apply method if you want to go with underscores:

    "Pillsy Pillsy Pillsy".foldRight(zero) { MyClass(_, _) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following use case: There's a class called Template and with that
I have a few questions regarding use-case diagram: If my system has register/login use-case
For example is it better to have: public class Case : EntityIdentifiable { public
I have a case, public class dictLanguage { public string EnglishText { get; set;
Case One Say you have a little class: class Point3D { private: float x,y,z;
I have a class mapped with a table, in my case in a declarative
I have a an Android ListView that has small (say, 1-5 frame) stutters as
I have a Java class: BinaryTree< t > that I am filling from a
I have a business class that contains two nullable decimal properties. A third property
I have an app that has a bunch of resources. Having read about javascript

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.