Result<T, E>.from constructor

Result<T, E>.from(
  1. T? value,
  2. E error
)

Creates a Result from the given nullable T value.

Creates:

  • Ok using the given T value if the given T value is not null.
  • Err using the given E value if the given T value is null.

Implementation

factory Result.from(T? value, E error) {
  return switch (value) {
    null => Err(error),
    _ => Ok(value),
  };
}