I have an Option[String]
.
I want to check if there is a string exists and if it\'s exists its not blank.
def isBlank( input : Option[Strin
I am from C# background and found Scala implicit methods similar to C# extensions
import com.foo.bar.utils.MyExtensions._
...
"my string".isNullOrEmpty // false
"".isNullOrEmpty // true
" ".isNullOrEmpty // true
" ".isNullOrEmpty // true
val str: String = null
str.isNullOrEmpty // true
Implementation
package com.foo.bar.utils
object MyExtensions {
class StringEx(val input: String) extends AnyVal {
def isNullOrEmpty: Boolean =
if (input == null || input.trim.isEmpty)
true
else
false
}
implicit def isNullOrEmpty(input: String): StringEx = new StringEx(input)
}