maybeWhen<_T> method

_T maybeWhen<_T>({
  1. required _T orElse(),
  2. _T ref(
    1. String ref
    )?,
  3. _T single(
    1. T value
    )?,
  4. _T list(
    1. List<CompVal<T>> values
    )?,
})

Implementation

_T maybeWhen<_T>({
  required _T Function() orElse,
  _T Function(String ref)? ref,
  _T Function(T value)? single,
  _T Function(List<CompVal<T>> values)? list,
}) {
  final v = this;
  if (v is CompValueRef<T>) {
    return ref != null ? ref(v.ref) : orElse.call();
  } else if (v is CompValueSingle<T>) {
    return single != null ? single(v.value) : orElse.call();
  } else if (v is CompValueList<T>) {
    return list != null ? list(v.values) : orElse.call();
  }
  throw Exception();
}