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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:57:57+00:00 2026-06-09T13:57:57+00:00

Please consider the following example def foo(a: Int, b: Int = 100) = a

  • 0

Please consider the following example

def foo(a: Int, b: Int = 100) = a + b
def bar(a: Int, b: Int = 100) = foo(a, b) * 2

This works, but note I have to supply the same default value to b in both functions. My intention is actually the following

def bar(a: Int, b: Int) = foo(a, b) * 2
def bar(a: Int)    = foo(a) * 2

But this becomes cumbersome when you have more optional arguments, and additional functions in the chain (such as baz that invokes bar in the same manner). Is there a more concise way to express this in scala?

  • 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-09T13:57:58+00:00Added an answer on June 9, 2026 at 1:57 pm

    I don’t think there is; if you compose foo with a doubling function:

    val bar = (foo _).curried((_: Int)) andThen ((_: Int) *2)
    // (please, please let there be a simpler way to do this...)
    

    you lose the default arguments, because function objects don’t have them.

    If it’s worth it in your use-case, you could create a case class containing your arguments which you pass instead of multiple individual ones, e.g.

    case class Args(a: Int, b: Int = 100, c: Int = 42, d: Int = 69)
    def foo(args: Args) = { import args._; a + b + c + d }
    def bar(args: Args) = foo(args) * 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following simple use case: public class Foo { public virtual int
Please, consider the following (I'm sorry for the amount of code; but this is
Please consider the following example: class Example { int &_m; public: /** * An
Please consider the following example code (from the lm doc): ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt
Please consider the following context from Innate : # Default application for Innate def
Please consider the following code, struct foo { foo() { std::cout << Constructing! <<
Please consider the following three .NET types: I have an interface, an abstract class,
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Please consider the following code and the explanation from this Mozilla tutorial Using web
please consider the following code: template <typename T> struct foo { template <typename S>

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.