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

  • Home
  • SEARCH
  • 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 8637105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:23:43+00:00 2026-06-12T10:23:43+00:00

I have the following function scala> def f1 = (prefix: String) => prefix +

  • 0

I have the following function

scala> def f1 = (prefix: String) => prefix + ".field"
f1: String => java.lang.String

And I’d like to define another function from f1, that fixed the value of prefix to p1, like this

def f2: () => String = () => f1("p1")

or more shortly

def f2 = () => f1("p1")

I think that the same could be achieved using Function.curried or f.curried and partialy applied functions, but I still couldn’t do it…

—

Having a look a this article I found a more verbose way of defining it. I guess the above syntax is just suger for this longer form…

scala> object f2 extends Function0[String] {
     | override def apply = f1("p1")
     | }
defined module f2

scala> f2
res37: f2.type = <function0>

scala> f2()
res38: java.lang.String = p1.field
  • 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-12T10:23:44+00:00Added an answer on June 12, 2026 at 10:23 am

    You can only “curry” functions with more than one argument. At least with the methods that Scala provides by default. With two parameters it works like this:

    val f2 = (prefix: String, foo:String) => prefix + ".field"
    val f1 = f2.curried("p1")
    

    If you want to do the same with Function1, you can “pimp” the class to add a new method:

    implicit def addCurry[A,B](f:Function[A,B]) = new Function1WithCurried(f)
    class Function1WithCurried[-A,+B](f:Function1[A,B]) {
      def curried:Function1[A,Function0[B]] = (x:A) => { () => f(x) }
    }
    
    def f1 = (prefix: String) => prefix + ".field"
    val f0 = f1.curried
    val f2 = f1.curried("p1")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following pattern matching case in a scala function: def someFunction(sequences: Iterable[Seq[Int]]):Seq[Int]
In Scala (2.7), if I have this function: def foo(args: Array[String]) = for (arg
I have a function like so: def print(name:String, surname:String) { println(name + + surname)
I have the following method: scala> def method_with_default(x: String = default) = {x +
sorry to overflow with so many questions. I have the following: (defun recursive-function (string)
Take the following function: def fMatch(s: String) = { s match { case a
Suppose I have a the following in Scala object Foo { var functions: List[String
I have the following toy function: def test[T](x: Option[List[Option[T]]]) { for (a <- x;
I have the following code in Scala-IDE: type myF = () => Boolean def
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (

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.