3

I have an enumeration like this:

object VersionTokens extends Enumeration {
  type VersionTokens = Value

  val ALL = Value("ALL")
  val CURRENT = Value("CURRENT")
}

Is there a way to check if any of the values in the enumeration exists in an array of strings?

pseudo code:

val versions = Array("CURRENT", "SOMETHING ELSE")
if(versions.contains(VersionTokens)) true
else false

// should return true since "CURRENT exists in the enumeration

1 Answer 1

7

You can, for example, check if the value set of your enumeration intersects your array :

VersionTokens.values.map(_.toString).toArray.intersect(versions).nonEmpty

or, less readable but faster:

VersionTokens.values.map(_.toString).toArray.exists(versions.contains)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.