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

The Archive Base Latest Questions

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

quite often I have code like the following if (operator == Equal || operator

  • 0

quite often I have code like the following

if (operator == Equal || operator == Missing || operator == Unknown) {

To make it less verbose and a little bit more readable sometimes I issue:

if (List(Equal, Missing, Unknown).contains(operator)) {

I know I could also issue pattern matching, like this

operator match {
  case Equal | Missing | Unknown => {

which brings another level of nesting braces

I was wondering if there’s some kind of method like

if (operator.isOneOf(List(Equal, Missing, Unknown))) {

—

edit:

to show how to use the different options that appeared here:

Using Set as a function

if (Set(1, 2, 3)(3)) {
  "Gotcha"
} else {
  "no luck..."
}

Using PartialFunction.cond

import PartialFunction.cond

if (cond(3) { case 1 | 2 | 3 => true }) {
  "Gotcha"
} else {
  "no luck..."
}

Implementing isOneOf

class ComparableWithIsOneOf[T](val value: T) {
  def isOneOf(values: T*): Boolean = {
    values.contains(value)
  }
}
object Comparison {
  object implicits {
    implicit def AnyToComparableWithIsOneOf[T](value: T): ComparableWithIsOneOf[T] = {
      return new ComparableWithIsOneOf(value)
    }
  }
}

import Comparison.implicits._

if (3.isOneOf(1, 2, 3)) {
  "Gotcha"
} else {
  "no luck..."
}

In the end I like the Set() version better, but I think the best is to stick with pattern matching, is more standard and idiomatic…

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

    You could just write

    if (Set(Equal, Missing, Unknown)(operator)) { ...
    

    Set being a function etc…

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

Sidebar

Related Questions

I quite often have rows of code like the following: UPDATE my_table SET name
Lately I often have to read Java code like this: LinkedHashMap<String, Integer> totals =
Quite often I find myself writing code like this: Dim oRenewalOrder = (From c
Preamble Using VTK library with C++, quite often I have to write something like
Python and Matlab quite often have integer date representations as follows: 733828.0 733829.0 733832.0
I have a bare repository I access over a SMB network. Quite often I
We make use of views and panels quite often in Drupal and a lot
I have a website where people can contact each other, and quite often people
I have some html code that look like this sample here : <html> <body>
Case Quite often I find myself staring at some old code that doesn't look

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.