1

i have two questions:

Firstly

when should i let the application crash?

Secondly:

this code from resoCoder. i do NOT understand it!!!!!!!!!!!! how could he crash the app if the todos is not right?!

 T getOrCrash() {
    // id = identity - same as writing (right) => right
    return value.fold((f) => throw UnexpectedValueError(f), id);
  }
Option<ValueFailure<dynamic>> get failureOption {
    return body.failureOrUnit
        .andThen(color.failureOrUnit)
        .andThen(todos.failureOrUnit)
        .andThen(
          todos
              .getOrCrash()      // is this crash is okay?!! why to do so???????!
              .map((todoItem) => todoItem.failureOption)
              .filter((o) => o.isSome())
              .getOrElse(0, (_) => none())
              .fold(() => right(unit), (f) => left(f)),
        )
        .fold((f) => some(f), (_) => none());
  }
  • I'm also confused by the use of getOrCrash, given that I spend so much time on null safety and trying to prevent app crashes at all costs. I'm guessing this would be caught somewhere up the tree, but still seems a strange way to handle invalid data. – David Conlisk Apr 07 '22 at 09:53

0 Answers0