when<R> method

Maybe<R>? when<R>({
  1. R some(
    1. T val
    )?,
  2. R none()?,
})

Pattern matching

if some and none all null Return None(null)

else when it has return Some(some(it)) or not has return Some(none(it))

Implementation

Maybe<R> when<R>({R some(T val)?, R none()?}) {
  if (this != null) {
    if (some != null) return Some(some(this!.value));
  } else {
    if (none != null) return Some(none());
  }
  return None<R>();
}