throwIfNot function

void throwIfNot(
  1. bool test,
  2. Error errorFactoryFunc()
)

Throws an Error if predicate test is not satisfied

Example:

throwIfNot(n > 1, () => ArgumentError("n must be greater than 0"));

Implementation

void throwIfNot(bool test, Error Function() errorFactoryFunc) {
  if (!test) {
    throw errorFactoryFunc();
  }
}