Reputation: 3080
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
Upvotes: 3
Views: 862
Reputation: 1316
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)
Upvotes: 7