getOrElse<Type> method

Type getOrElse<Type>(
  1. Type fallback
)

The getOrElse method which receives a parameter to return as a fallback value, when the value is a Nothing, or there is no value in the Just.

Implementation

Type getOrElse<Type>(Type fallback) {
  return when(
    nothing: () => fallback,
    just: (value) {
      if (value == null) {
        return fallback;
      } else {
        return value is Type ? value as Type : fallback;
      }
    },
  );
}