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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:48:07+00:00 2026-06-12T19:48:07+00:00

Possible Duplicate: What's the rationale behind curried functions in Scala? I have two difference

  • 0

Possible Duplicate:
What's the rationale behind curried functions in Scala?

I have two difference ways to declare a function: 1) use currying. 2)use function as parameter.

Here is my code :

def transform(f: Double => Double)(input: Double) = {
  f(input)
}                                                 

def transformVer2(f: Double => Double, input: Double) = {
  f(input)
}                                                 

transform(x=>x*x)(10)                             //> res8: Double = 100.0
transformVer2(x=>x*x, 10)                         //> res9: Double = 100.0

I don’t know what the real difference of two above declare of a function. Please tell me.

Thanks 🙂

  • 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-12T19:48:08+00:00Added an answer on June 12, 2026 at 7:48 pm

    The former employs currying, the latter is something you’re probably more familiar with from languages like C, C++, etc.

    Currying is something that is prominent in functional programming languages.. functional programming languages place the idea of functions and function chaining in high regard so something like

    def transform(f: Double => Double)(input: Double)
    

    Can be seen as something that takes as a single argument a function Double => Double and returns another function that takes as a single argument a Double and returns a Double.

    As Programming in Scala discusses, function currying also let’s us do some nifty things, two of which come to mind are

    1. type inference
    2. new control abstractions

    For type inference, consider something like foldLeft.

    val myVector = Vector(1, 2, 3, 4)
    myVector.foldLeft(0.0)(_ + _)
    

    foldLeft is curried, and us specifying 0.0 as the initial value let’s the type inferencer know we want our final result to be a Double.

    For new control abstractions, we can do something like

    def doWithFileAndClose(file: File)(func: () => Unit): Unit =
      try { func() } finally { file.close }
    

    which would be used like

    doWithFileAndClose("somefile.txt") {
      /* do stuff */
    }
    

    This takes advantage that Scala will accept curly braces in place of parentheses, which makes the above look just like familiar control structures such as for and while loops.

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

Sidebar

Related Questions

Possible Duplicate: What is the rationale behind having companion objects in Scala? Thanks for
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: What is the difference between a function expression vs declaration in JavaScript?
Possible Duplicate: Trying to get tables next to each other horizontal I have two
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Conflicting boolean values of an empty JavaScript array What is the rationale
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like

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.