Apply side effect only if OptArg is empty.
Apply side effect only if OptArg is empty. It's a bit like foreach for OptArg.Empty
- code to be executed if optArg is empty
the same optArg
captionOptArg.forEmpty(logger.warn("caption is empty")).foreach(setCaption)
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 andOption
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 orOption
as soon as possible (usingtoOpt
,toNOpt
andtoOption
methods).