Whats the most elegant way to add two numbers that are Optional

后端 未结 8 825
既然无缘
既然无缘 2021-02-08 03:29

I need to perform an add operation on two big decimals that are wrapped optionals:

Optional ordersTotal;
Optional newOrder;
<         


        
8条回答
  •  灰色年华
    2021-02-08 03:54

    You could use a stream of optionals. Then you can make a stream of bigdecimals, and then reduce those bigdecimals, or else return 0.

    This has the advantage that you don't have to change the code if you want to do that more than two optionals.

    (code can be added later if needed, currently I don't have access to a computer)

提交回复
热议问题