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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:11:00+00:00 2026-06-11T17:11:00+00:00

Possible Duplicate: Can anyone explain how the symbol “=>” is used in Scala val

  • 0

Possible Duplicate:
Can anyone explain how the symbol “=>” is used in Scala

val list = List("abc", "cde", "fg")
list.count (s => s.length == 3)

The above code snippet returns the number of string elements in list whose length is equal to 3. But I’m not able to understand the snippet as I’m having trouble to grasp the usage of the => operator in this context. Any explanation will be realy helpful.

  • 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-11T17:11:01+00:00Added an answer on June 11, 2026 at 5:11 pm

    Yeah, Scala can be pretty hard to understand. I’ll do my best to explain it, though I might not get it right either.

    The List.count method takes as a parameter a block of code that returns a boolean.

    Blocks are just little snippets of code and can be created in many ways eg by enclosing code in { }

    In the scala docs this is described as

    def count (p : (A) => Boolean) : Int
    

    so count takes a parameter p which is a block that takes an argument of type A and returns a Boolean

    So in this example:

    s => s.length == 3
    

    is a block of code. Blocks usually follow the format

    [arguments] => [Code to execute]
    

    So in this instance s is the input to the block and s.length == 3 is the code that should return a boolean. You can name the arguments whatever you like, so long as they are in the correct order.

    When using a method that iterates over a collection, eg count, map, each, etc, the argument passed will be the current item in the collection it is iterating over.

    If you want to learn more about it you should check out the Coursera course that is being run my Martin Odersky (the creator of scala) and will be covering details like this in great detail: https://www.coursera.org/course/progfun

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

Sidebar

Related Questions

Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Can anyone explain the
Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following
Possible Duplicate: Difference between i++ and ++i in a loop? Can anyone explain what's
Possible Duplicate: Python init and self what do they do? Can anyone explain what
Possible Duplicate: Can anyone explain IEnumerable and IEnumerator to me? What are the differences
Possible Duplicate: Java Generics Hi, Can anyone please explain the difference of the three
Possible Duplicate: Absolute Beginner's Guide to Bit Shifting? anyone can explain me that operator
Possible Duplicates: function overloading in C Does C support overloading ? Can anyone explain
Possible Duplicate: [python]: path between two nodes Can anyone point me to some resources
Possible Duplicate: self.prop=nil; vs. [prop release];prop=nil; Can anyone help, What is the difference between

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.