Apply side effect only if OptRef is empty.
Apply side effect only if OptRef is empty. It's a bit like foreach for OptRef.Empty
- code to be executed if optRef is empty
the same optRef
captionOptRef.forEmpty(logger.warn("caption is empty")).foreach(setCaption)
Like Opt but has better Java interop thanks to the fact that wrapped value has type
A
instead ofAny
. For example, Scala method defined like this:will be seen by Java as:
public void takeMaybeString(String str);
and
null
will be used to represent absence of value.This comes at the cost of
A
having to be a nullable type. Also, empty value is represented internally usingnull
which unfortunately makes OptRef suffer from SI-7396 (hashCode
fails onOptRef.Empty
which means that you can't add OptRef values into hash sets or use them as hash map keys).