optical.converter.utils.ifnone

optical.converter.utils.ifnone(x: Any, y: Any, transform: Optional[Callable] = None, type_safe: bool = False)[source]

if x is None return y otherwise x after applying transofrmation transform and casting the result back to original type if type_safe

Parameters
  • x (Any) – returns x if x is not none

  • y (Any) – returns y if x is none

  • transform (Optional[Callable], optional) – applies transform to the output. Defaults to None.

  • type_safe (bool, optional) – if true, tries casting the output to the original type. Defaults to False.