intoUnchecked<S2> method

  1. @override
Err<S2, F> intoUnchecked<S2>()
override

Changes the Ok type to S2. See into for a safe implementation of intoUnchecked. This is usually used when "this" is known to be an Err and you want to return to the calling function, but the returning function's Ok type is different from this Ok type.

Throws an Error if cannot cast the Ok value to S2. Example of proper use:

Result<int,String> someFunction1 () {...}

Result<String,String> someFunction2() {
  Result<int,String> result = someFunction1();
  if (result.isErr()) {
    return result.intoUnchecked();
  }
...

Note how above, the S2 value is inferred by Dart, this is usually what be want rather than being explicit. In Rust, "intoUnchecked" is handled by the "?" operator, but there is no equivalent in Dart.

Implementation

@override
@pragma("vm:prefer-inline")
Err<S2, F> intoUnchecked<S2>() {
  return Err(err);
}