Skip to content

Add helpers to chain StatusCode dependent executions

Marco Clemencic requested to merge clemenci/Gaudi:monadic-statuscode into master

After !514 (merged) it is not possible to write code like:

StatusCode someFunc() {
  return func1() && func2() && func3();
}

The change I'm proposing allows something equivalent:

StatusCode someFunc() {
  return func1().andThen(func2).andThen(func3);
}

and more:

StatusCode myFunction() {
  return subFunction()
      .andThen([]() {
        do_something();
      })
      .andThen(anotherFunction)
      .andThen([]() {
        if (is_special_case())
          return do_something_else();
        return StatusCode::SUCCESS;
      });
}

or, for functions not returning StatusCode:

void myFunction() {
  doSomething()
      .andThen( doSomethingElse )
      .orThrow( "some error", "myFunction" )
      .andThen( moreActions )
      .orThrow( "too bad, we were nearly there", "myFunction" );
}
Edited by Marco Clemencic

Merge request reports