Functional Programming - FindFirst

Card Puncher Data Processing

Functional Programming - FindFirst

About

This page is about the FindFirst function in the functional programming paradigm.

As its name indicates, it will find the first element in the collection.

It's generally followed by a delivery function such as:

  • ifPresent - if you want to do other operations
  • or orElseThrow - if you want to stop and throw an exception

Example

Java: FindFirst or throw

Example in Java:

list
  .stream()
  .filter(txt -> txt.startsWith(startsWith))
  .findFirst()
  .orElseThrow(() -> new NoSuchElementException("No element found"));







Share this page:
Follow us:
Task Runner