On 1/29/26 4:28 PM, kdevel wrote:

> Maybe the OP favors a different definition of "fail fast"

Yes.

> as the
> function under close scrutiny is not failing at all.

What the OP means is implied by the following two facts:

- The subject line says "empty result"

- One of the operations is named someExpensiveOperation()

Adding the fact that the OP could have written the following and be done with it:

    auto result = someExpensiveOperation()
        .filter!(a => a != "expensive")
        .map!(a => tuple!("value", "numLetters")(a, a.length));

   return (fail
           ? typeof(result).init
           : result);

That code would compile and work but the code would have to execute unnecessary operations even in the fail case.

The OP's question was about how to return an empty result without wasting CPU cycles.

>        FailFast also refers to some programming techniques that cause
>        an exception to be thrown or other redirection of control to
>        occur upon meeting certain conditions. [...]
>
>        http://c2.com/

I've been throwing exceptions for a very long time via 'throw', 'enforce', 'assert', etc. I've never heard of that definition before. I've been taking consultants with a lot of grains of salt for a long time now, especially ones who have been on the OOP wagon. I value engineering over a lot of things...

Ali

Reply via email to