OptArg is like Opt except it's intended to be used to type-safely express optional method/constructor
parameters while at the same time avoiding having to explicitly wrap arguments when passing them
(thanks to the implicit conversion from A to OptArg[A]). For example:
def takesMaybeString(str: OptArg[String] = OptArg.Empty) = ???
takesMaybeString() // default empty value is used
takesMaybeString("string") // no explicit wrapping into OptArg required
Note that like Opt, OptArg assumes its underlying value to be non-null and null is translated into OptArg.Empty.
It is strongly recommended that OptArg type is used ONLY in signatures where implicit conversion A => OptArg[A]
is intended to work. You should not use OptArg as a general-purpose "optional value" type - other types like
Opt, NOpt and scala.Option serve that purpose. For this reason OptArg deliberately does not have any "transforming"
methods like map, flatMap, orElse, etc. Instead it's recommended that OptArg is converted to Opt,
NOpt or scala.Option as soon as possible (using toOpt, toNOpt and toOption methods).
OptArg is like Opt except it's intended to be used to type-safely express optional method/constructor parameters while at the same time avoiding having to explicitly wrap arguments when passing them (thanks to the implicit conversion from
A
toOptArg[A]
). For example:Note that like Opt, OptArg assumes its underlying value to be non-null and
null
is translated intoOptArg.Empty
.It is strongly recommended that OptArg type is used ONLY in signatures where implicit conversion
A => OptArg[A]
is intended to work. You should not use OptArg as a general-purpose "optional value" type - other types like Opt, NOpt and scala.Option serve that purpose. For this reason OptArg deliberately does not have any "transforming" methods likemap
,flatMap
,orElse
, etc. Instead it's recommended that OptArg is converted to Opt, NOpt or scala.Option as soon as possible (usingtoOpt
,toNOpt
andtoOption
methods).