On Saturday, 7 November 2020 at 15:49:13 UTC, James Blachly wrote:

```
retval = i > 0 ? Success!int(i) : Failure("Sorry");
```

casting each to `Result` compiles, but is verbose:

```
return i > 0 ? cast(Result) Success!int(i) : cast(Result) Failure("Sorry");
```

** Could someone more knowledgeable than me explain why implicit conversion does not happen with the ternary op, but works fine with if/else? Presumably, it is because the op returns a single type and implicit conversion is performed after computing the expression's return type? If this somehow worked, it would make the SumType package much more ergonomic **

It's just that tenary requires the same type in both branches. It was already so in C.


return i > 0 ? (retval = Success!int(i)) : (retval = Failure("Sorry"));

should work

Reply via email to