I'm trying to create a map based on conditions. Here's the general workflow in pseudocode:

```

def createMyMap(input: String): Map[String, String] = {
  val stringArray = input.split(",")

  stringArray.map(element => {
    if (condition) {
      newKey -> newVal
    }
  }).toMap
}

```

and I see two compile errors:

1. `No implicits found for parameter ev: Any <:< (T_, U_)` in the `toMap` call
2. For the method `createMyMap`

```
Type mismatch.
Required: scala.Predef.Map [String, String]
Found: scala.collection.immutable.Map[Nothing, Nothing]

```

This makes sense since the compiler doesn't know how to create the map if the condition isn't fulfilled. For example, if I add this in the method:

```
if (condition) {
  newKey -> new Val
} else {
  null
}

```

then it'll compile. I'm just not too sure how to approach the `else` - how do I avoid this kind of problem? I'm running into this because I only want to create a map entry if a condition is fulfilled.