I have a Java enum which represents the side of an order (`enum Side {ASK, BID}`) and I'm constantly writing code with which I'd like to use the ternary operator, e.g.:

```
BigDecimal orderPrice = order.getSide() == Side.ASK ? calcAskPrice(order) : calcBidPrice(order)

```

The issue is that I want to future proof the code so that it fails if the provided value is neither `ASK` nor `BID`. The obvious solution seems unnecessarily verbose to me, because the pattern needs to be repeates tens (maybe even hundreds?) of times throughout the code. I'd rather not have this everywhere:

```
BigDecimal orderPrice;
if (order.getSide() == Side.ASK) {
   orderPrice = calcAskPrice(order);
} else if (side == Side.BID) {
   orderPrice = calcBidPrice(order);
} else {
   throw new IllegalArgumentException("The provided order must have a side that is either ASK or BID");
}

```

Instead I'd prefer a more functional approach, like the ternary operator.

A safer approach works, but is (i) also verbose and (ii) confusing:

```
BigDecimal orderPrice = order.getSide() == Side.ASK ? calcAskPrice(order) : order.getSide() == Side.BID ? calcBidPrice(order) : null;
assertNotNull(orderPrice);

```

Thinking about my desired syntax, I decided to add some methods to the enum such that I could write:

```
BigDecimal orderPrice = order.getSide().ifAsk(calcAskPrice(order)).ifBid(calcBidPrice(order)).elseFail();

```

This was implemented via an object that would store the value of the enum along with the two result values, and whose `elseFail()` method would return the appropriate result or fail. I was extremely satisfied with this, until (in pursuit of a separate issue) I noticed that my little evaluator object had a rather large footprint, but in terms of object creation & CPU time.

In retrospect this makes sense, because the code processes large numbers of updates, and is scattered with checks to the order side.

I'm now left with trying to think up a performant/low overhead way to provide similar syntax. The easiest solution that I can think of is to have a method on the enum:

```
public <T> T ifAskBid(T askResult, T bidResult) {
   // . . .
}

```

but I'm curious if anybody can think of a nicer solution.