The accepted answer to "How to convert a Some(“ ”) to None in one-line?" took the form:
def convert(x: Option[String]) : Option[String] =
x.map(_.trim()).filterNot(_.isEmpty())
My problem is that I can't figure out how to find by what means the collection returned by filterNot is converted to an Option. I looked at the Scaladoc for Option constructors, Option Object, Predef, Seq, and Seq Object. I figure there's probably an implicit somewhere, but how does one go about finding it?
map
andfilter
methods. But these are monad operations (along withflatMap
). Sure, you can think of Options as like collections (there's even an implicit conversion toList
) but it's irrelevant for this question. It's like sayingOption
is like aFoo
because they both have atoString
method. – Unwarrantable