Roninio
Roninio

Reputation: 1771

Search for a char in the key of a Map

I would like to make this method high-order function.

The idea is Sending a Map of key value and search for a char "." Dot if exists in key.

  def findChar(mymap: Map[String, Any]): Boolean = {
    val pattern = "^.*\\..*$".r
    mymap.keys.foreach {
      case pattern() => return true
      case _ => None
    }
    return false
  }

i am calling this function

if (findChar(attributes)) {
            DO something

 } else {
           DO something else }

how can i use the "exsits" method here?

Upvotes: 0

Views: 69

Answers (1)

Haris Osmanagić
Haris Osmanagić

Reputation: 1285

One way to do it, if you explicitly need exists:

map.keys.exists(_.contains("."))

Upvotes: 2

Related Questions