Functional Programming - FindFirst

Imperative Vs Functional


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


Java: FindFirst or throw

Example in Java:

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

Discover More
Imperative Vs Functional
Code - Functional programming (FP) - Collection Operations

Functional programming (FP) defines standard operations on collections. It is a declarative paradigm that treats computation as the evaluation of mathematical functions. Most of the operations, you perform...

Share this page:
Follow us:
Task Runner