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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:08:51+00:00 2026-06-15T15:08:51+00:00

I was thinking about how to go about currying a method with varargs, and

  • 0

I was thinking about how to go about currying a method with varargs, and I realized that I don’t even have an intuition for how one would go about doing it. Ideally, it would be something that would let you start using it whenever you liked, and then end it with an iterable.

def concat(strs: String*) = strs.mkString

val curriedConcat = concat.curry

curriedConcat("OK")("hello", "world")("welcome")(Seq(): _*)

Is there support for this in scala? I couldn’t figure out how to do anything more than bind it to a function of length N and then curry that.

  • 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-15T15:08:51+00:00Added an answer on June 15, 2026 at 3:08 pm

    Using Scala 2.10 and shapeless:

    import shapeless.Nat._
    import shapeless.{Nat, Succ}
    
    trait Curry[T, Res, N <: Nat] {
      type Out
      def apply(as: Seq[T], f : Seq[T] => Res) : Out
    }
    
    object Curry {
      implicit def curry[Out0, T, Res, N <: Nat](implicit curry : CurryAux[Out0, T, Res, N]) = new Curry[T, Res, N] {
        type Out = Out0
        def apply(as: Seq[T], f : Seq[T] => Res) = curry(as, f)
      }
    }
    
    trait CurryAux[Out, T, Res, N <: Nat] {
      def apply(as: Seq[T], f : Seq[T] => Res) : Out
    }
    
    object CurryAux {
      implicit def curry0[Res, T] = new CurryAux[Res, T, Res, _0] {
        def apply(as: Seq[T], f : Seq[T] => Res) : Res = f(as)
      }
    
      implicit def curryN[Out, T, Res, N <: Nat](implicit c : CurryAux[Out, T, Res, N]) =
        new CurryAux[T => Out, T, Res, Succ[N]] {
          def apply(as: Seq[T], f : Seq[T] => Res) : (T => Out) = (a: T) => c(as :+ a, f)
        }
    }
    
    implicit class CurryHelper[T, Res](f : Seq[T] => Res) {
      def curry[N <: Nat](implicit c : Curry[T, Res, N]): c.Out = c(IndexedSeq[T](), f)
    }
    

    Usage:

    scala> def concat(strs: String*) = strs.mkString
    concat: (strs: String*)String
    
    scala> val test = ( concat _ ).curry[_3]
    test: String => (String => (String => String)) = <function1>
    
    scala> test("1")("2")("3")
    res0: String = 123
    

    Without shapeless:

    class CurryHelper[T, Res](f: Seq[T] => Res, as: Seq[T]) {
      def myCurry() = this
      def apply(ts: T*) = new CurryHelper(f, as ++ ts)
      def apply(ts: Seq[T]) = f(as ++ ts)
    }
    
    implicit def toCurryHelper[T, Res](f: Seq[T] => Res) = new CurryHelper(f, IndexedSeq[T]())
    
    scala> def concat(strs: String*) = strs.mkString
    concat: (strs: String*)String
    
    scala> val test = ( concat _ ).myCurry
    test: CurryHelper[String,String] = CurryHelper@4f48ed35
    
    scala> test("1")("2")("3", "4")(Nil)
    res0: String = 1234
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just thinking about the best way to build an Order form that would (from
For about a year I have been thinking about writing a program that writes
Just thinking about my page titles and wondering which one to have keyword |
guys i am thinking about one sorting method,it is called sleep sort #include <stdlib.h>
I'm thinking about a database design that will have two tables Members and Groups.
Thinking about avoiding code replication, I got a question that catches me every time
I am thinking about making a program that will need to send input and
I have been thinking about a way solve a problem I have and I'm
I'm thinking about trying MongoDB to use for storing our stats but have some
I have been thinking about building a client to client program. But the way

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.