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
Ainstead ofAny. For example, Scala method defined like this:will be seen by Java as:
public void takeMaybeString(String str);and
nullwill be used to represent absence of value.This comes at the cost of
Ahaving to be a nullable type. Also, empty value is represented internally usingnullwhich unfortunately makes OptRef suffer from SI-7396 (hashCodefails onOptRef.Emptywhich means that you can't add OptRef values into hash sets or use them as hash map keys).