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

The Archive Base Latest Questions

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

How does the below scala implementation of FizzBuzz work ? Here is what I

  • 0

How does the below scala implementation of FizzBuzz work ?

Here is what I think, but im not sure if im on the right track :
The use of => Is this a high order function, if so it is just returning a String
i is a String which contains either "FizzBuzz" , "Fizz" or "Buzz"

package fizzbuzz

object FizzBuzz {
  def main(args : Array[String]) {
    (1 until 100).map(_ match {                
      case i : Int if ((i % 3) == 0 && (i % 5) == 0) => "FizzBuzz"
      case i : Int if ((i % 3) == 0) => "Fizz"
      case i : Int if ((i % 5) == 0) => "Buzz"
      case i : Int => i.toString
    }).foreach(println _)
  }
}
  • 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-12T15:23:11+00:00Added an answer on June 12, 2026 at 3:23 pm

    The use of => Is this a high order function

    No, the => here is part of the match-case syntax. It separates the pattern for the given case from the case’s body, i.e. the syntax is case pattern => body where pattern a pattern to match against the given value and body is the code that’s supposed to execute if pattern matches.

    The code works by iterating over the numbers from 1 until 100 (by using map) and matching each number against the patterns in the match block. The patterns use pattern guards to check whether each number is divisible by 3, 5 or both (or neither). The result is a sequence of strings. The code then iterates over that sequence using foreach and prints each item using println.

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

Sidebar

Related Questions

The code below does not work but meant to illustrate what I want to
Why does this graphml file below does not render the node color properly in
The below does not compile: Func<int, int> fac = n => (n <= 1)
I am trying to find out why the code below does not seem to
Below class does not compile, if I declare Functions as an object instead of
This one is pretty straightforward. Why does the code below cause the error below?
Can any one tell what does below given lines means? The lines below are
What does the below JavaScript mean? Why is the function embedded inside ()? (function()
The routine below does two scans over an input stream of hypertext. The first
Why does the below code give Seg. Fault at last line? char* m=ReadName(); printf(\nRead

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.