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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:44:08+00:00 2026-06-11T11:44:08+00:00

I was reading this blog post and i was not able to understand a

  • 0

I was reading this blog post and i was not able to understand a part of the code.

object O {
  def maximum(x: List[Int]): Int = x match {
  case Nil => error("maximum undefined for empty list")
  case x :: y :: ys => maximum((if(x > y) x else y) :: ys)
  case x :: _ => x
 }
}

Please explain the code maximum((if(x > y) x else y) :: ys)

How the if condition can be a part of the method maximum ?
I understand that if condition is not exactly a parameter.

  • 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-11T11:44:10+00:00Added an answer on June 11, 2026 at 11:44 am

    In Scala, if is an expression, not a statement.

    Try this in the REPL:

    scala> val x=1; val y=0
    x: Int = 1
    y: Int = 0
    
    scala> val test=if(x > y) x else y
    test: Int = 1
    

    if evaluates to 1 and 1 is assigned to test. In Java if could be expressed with the conditional operator (x > y) ? x : y

    Now, you have a function called maximum that takes a List[Int] as a parameter.
    maximum((if(x > y) x else y) :: ys) calls maximum (recursively) with a list obtained prepending one between x and y (depending on what the if evaluates to) to ys.

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

Sidebar

Related Questions

Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
Should be an easy one. I thought, from reading this blog post that I
I was reading a blog where the writer said this Code doesn’t exist unless
I have been reading this blog post and this stack overflow post but I
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
I was reading this blog post on ASP.NET MVC 2's new model validation and
Recently, I've got a dangerous idea into my head after reading this blog post.
Reading this Brad Wilson blog post , I'm coming across several attributes (e.g., DisplayFormatString
Reading this blog post it mentions you can get your DI container to automatically
I was reading this example: http://blog.ondrejsv.com/post/AppSettingsReader-and-reading-typed-and-nullable-application-settings.aspx and I noticed in this line of code:

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.