Functional Programming - FindFirst

Card Puncher Data Processing

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"));





Discover More
Card Puncher Data Processing
What is Functional programming (FP) - Collection Operations

In Functional programming (FP), you will pass functions to other functions as parameters. It is a declarative paradigm that treats computation as the evaluation of mathematical functions. With functional...



Share this page:
Follow us:
Task Runner