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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:12:37+00:00 2026-05-13T20:12:37+00:00

I have seen this usage of Function.tupled example in another answer : Map(1 ->

  • 0

I have seen this usage of Function.tupled example in another answer: Map(1 -> "one", 2 -> "two") map Function.tupled(_ -> _.length).

It works:

scala> Map(1 -> "one", 2 -> "two") map Function.tupled(_ -> _.length)
<console>:5: warning: method tupled in object Function is deprecated: 
Use `f.tuple` instead
       Map(1 -> "one", 2 -> "two") map Function.tupled(_ -> _.length)
                                                ^
res0: scala.collection.immutable.Map[Int,Int] = Map(1 -> 3, 2 -> 3)

It seems I can do without if I don’t want to use the placeholder syntax.

scala> Map(1 -> "one", 2 -> "two") map (x => x._1 -> x._2.length)
res1: scala.collection.immutable.Map[Int,Int] = Map(1 -> 3, 2 -> 3)

The direct use of the placeholder syntax does not work:

scala> Map(1 -> "one", 2 -> "two") map (_._1 -> _._2.length)
<console>:5: error: wrong number of parameters; expected = 1
       Map(1 -> "one", 2 -> "two") map (_._1 -> _._2.length)

How does Function.tupled work? There seem to be a lot happening in Function.tupled(_ -> _.length). Also how would I use it to not get the deprecation warning?

  • 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-05-13T20:12:37+00:00Added an answer on May 13, 2026 at 8:12 pm

    UPDATE
    The deprecation was removed today, in response to this problem.


    Tupling a function is simply adapting FunctionN[A1, A2, ..., AN, R] to a Function1[(A1, A2, ..., AN), R]

    Function.tuple is deprecated in favour of FunctionN#tupled. A (possibly unintended) consequence of this is that the type inferencer can’t infer the parameter types in:

    scala> Map(1 -> "one", 2 -> "two") map (_ -> _.length).tupled                 
    <console>:5: error: missing parameter type for expanded function ((x$1, x$2) => x$1.$minus$greater(x$2.length))
           Map(1 -> "one", 2 -> "two") map (_ -> _.length).tupled
                                            ^
    <console>:5: error: missing parameter type for expanded function ((x$1: <error>, x$2) => x$1.$minus$greater(x$2.length))
           Map(1 -> "one", 2 -> "two") map (_ -> _.length).tupled
    

    Any of these will work:

    scala> Map(1 -> "one", 2 -> "two") map { case (a, b)  => a -> b.length }
    res8: scala.collection.immutable.Map[Int,Int] = Map(1 -> 3, 2 -> 3)
    
    scala> Map(1 -> "one", 2 -> "two") map ((_: Int) -> (_: String).length).tupled           
    res9: scala.collection.immutable.Map[Int,Int] = Map(1 -> 3, 2 -> 3)
    
    scala> Map(1 -> "one", 2 -> "two") map ((p: (Int, String))  => p._1 -> p._2.length)
    res12: scala.collection.immutable.Map[Int,Int] = Map(1 -> 3, 2 -> 3)
    

    I suggest you read the answers to this recent question to get a deeper understanding of ‘_’ in function literals, and how type inferencing works:

    In Scala, what is the difference between using the `_` and using a named identifier?

    UPDATE

    In answer to the comment, it does.

    scala> val f = (x:Int, y:String) => x + ": " + y
    f: (Int, String) => java.lang.String = <function2>
    
    scala> f.tupled
    res0: ((Int, String)) => java.lang.String = <function1>
    
    scala> Map(1 -> "1") map f.tupled
    res1: scala.collection.immutable.Iterable[java.lang.String] = List(1: 1)
    

    This requires Scala 2.8. Note that Map#map can result in another map, if the return type of the function is a Tuple2, otherwise a List, as above.

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

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You will need three variables to get this to work:… May 14, 2026 at 7:26 pm
  • Editorial Team
    Editorial Team added an answer Use $('#form :input:visible:enabled:first').focus(); during document ready. May 14, 2026 at 7:26 pm
  • Editorial Team
    Editorial Team added an answer Microsoft's position has been the same for a while now.… May 14, 2026 at 7:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.