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

  • Home
  • SEARCH
  • 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 6731681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:33:28+00:00 2026-05-26T10:33:28+00:00

So in a comment from another question , I just saw this example for

  • 0

So in a comment from another question, I just saw this example for counting the number of L’s in a string:

"hello".count('l'==)

And crazy enough..it works.

Starting with the fully expanded version, we have:

"hello".count(ch => ch == 'l')

Which can then be reduced to:

"hello".count(_ == 'l')

But then we can do:

"hello".count('l'==)

And I’m going like … ??? …

Presumably Scala is inferring that we must have meant to add an _ at the end of the comparison. IMO, this is where things start getting super weird; this seems overboard to me. Can anyone explain the thinking behind allowing this syntax, or shed further light on this?

If you think this is cool, then how do we justify not assuming that people may want the == operator too, so that could be omitted? Then we could have:

"hello".count('l')

I think I’m having flashbacks to the nightmare of having 10^99999 possible ways of doing things in perl…

  • 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-26T10:33:29+00:00Added an answer on May 26, 2026 at 10:33 am

    The “fully expanded” version you started out with is actually backwards, it should be:

    "hello".count(ch => 'l' == ch)
    

    However, == isn’t considered special by the Scala language, it’s just another method of Any. So to expand even further:

    "hello".count(ch => 'l'.==(ch))
    

    But hang on… The count method from TraversableOnce is expecting a function with the signature (A) ⇒ Boolean as an argument. The signature of Any.==() happens to be Any ⇒ Boolean, so that fits neatly without needing to be wrapped in another anonymous function. So instead we can just say:

    "hello".count('l'.==)
    

    or, omitting the dots:

    "hello" count('l' ==)
    

    Why don’t we omit the == operator too? Well, I guess you could define countEqual as count(a => a ==) (or, more succinctly, count(_ ==)) if you really wanted to… But you could just as well define countLowerCase or whatever. The main point here is that == isn’t special.

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

Sidebar

Related Questions

I have this string: comment_1234 I want to extract the 1234 from the string.
Hey this question is in reply to Joel Hooks 's comment on an older
Reference another SO question I had, I was given this article about Twitter moving
My table is comment_likedislike. It has the comment_counterid, comment_counter, comment_id(which is from another table)
Is it possible to generate a set of wiki pages from XML comment file
When I read source from open source projects I often find a comment line
I installed drupal-6.16. I applied the patch from the post http://drupal.org/node/222926#comment-930745 . It works
I'm looking for Python code that removes C and C++ comments from a string.
This is probably a simple question, I have a form that you put in
this oughta be an easy one. My question is very similar to this one

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.