Friday, 12 January 2018

Using Optional.map

I found the following example of code in our code base, it was in a method that got called with a model which is a collection of ModelNodes.

Optional<ModelNode> node = model.stream().findFirst();
Optional<String> detailCode = node.isPresent() ?
  Optional.of(node.get().getValue()) : Optional.empty();

Luckily it can be rewritten a deal more concisely with the .map function available in the Optional class.

Optional<String> aangifteDetCode = model.stream().findFirst().map(ModelNode::getValue);

The codebase just got a little better.

Tuesday, 2 January 2018

All the Best Wishes for 2018!

For those of you who read my blog, my sincerest best wishes for 2018 for you.

Let me leave you now with one of my favorite quotes (from Kung fu Panda, but it's been around for some time):

“Yesterday is history, tomorrow is a mystery, but today is a gift. That is why it is called the “present.” .”
- Oogway, Kung Fu Panda