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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:42:31+00:00 2026-06-04T11:42:31+00:00

def first[A] :Tuple2[A,_] => A = ( pair :Tuple2[A,_] ) => pair._1 val name

  • 0
def first[A] :Tuple2[A,_] => A  = ( pair :Tuple2[A,_] ) => pair._1
val name = first( ("Anna", 23) )

“If you take a closer look at line 2, what you see here is a method call which returns a newly created function of type Tuple2[String,Any] => String (since the compiler kicks in and infers the needed type for applying to person). Although the whole expression looks like an ordinary method call, it’s in fact a method call (to a factory method without any parameter) and a function call which follows afterwards. ” — this is the explanation of the above code.

I am not able to reason about the first step of the above process (the process creating a function object). Can someone write out a “human compiler” procedure explicitly?

EDIT: I think the fully expanded logic for line 2 should be the following two lines

val firstAsFunc= first[String]; 
val name = firstAsFunc(("Anna", 23))
  • 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-04T11:42:33+00:00Added an answer on June 4, 2026 at 11:42 am

    I’m not sure to break it down further. Here’s what I can think of — I hope you get it, or that someone else is feeling more clever than I.

    scala> val func = first[String] // method call
    func: Tuple2[String, _] => String = <function1>
    
    scala> val name = func( ("Anna", 23) )
    name: String = Anna
    

    The problem with the above is that func is really a getter — a method call itself — so I’m hardly changing anything.

    EDIT

    I’m not sure what you mean by formal parameter. The method first doesn’t have value parameters, just type parameters. Trying to pass a value parameter to it would be a syntactical error.

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

Sidebar

Related Questions

I have this method private def getAddresses(data: List[Int], count: Int, len: Int): Tuple2[List[Address], List[Int]]
def findDistance(): first_coord = raw_input(Enter first coordinate set (format x, y): ).split(,) second_coord =
Given this class: class First def to_s ; Hello World ; end end and
I'll post my code first, and then ask questions. def menu(**arg): if len(arg) ==
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like
I have one Class with 2 methods. The first method is called by the
I have a method that returns the first day of the first week of
def sortProfiles(p): return sorted(p, key=itemgetter('first_name')) I have a list with dictionaries. This function allows
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def partial(template, *args) options = args.extract_options! options.merge!(:layout => false) if collection = options.delete(:collection) then

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.