Skip to content

io microsphere util Functional

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

Functional

Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/util/Functional.java

Overview

A fluent API utility class for performing chained operations on a value of type V.

This class allows for conditional processing (#on(Predicate)), value transformation (#as(Function)), and side-effect execution (#apply(Consumer)) in a fluent and readable manner.

The state of the object is not thread-safe due to the mutable internal state tracking (e.g., matched). It's designed for single-threaded use or must be externally synchronized when used concurrently.

Example Usage

`// Example 1: Conditional mapping
String result = Functional.value("Hello")
    .on(s -> s.length() > 3)
    .as(String::toUpperCase)
    .value();

// Example 2: Conditional side effect
Functional.value(42)
    .on(n -> n > 40)
    .apply(n -> System.out.println("Value is: " + n));

// Example 3: Named functional operation
Functional.of("user", user)
    .on(u -> u.isActive())
    .as(User::getName)
    .apply(name -> System.out.println("Active user: " + name));
`

Declaration

public class Functional<V>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Example 1: Conditional mapping
String result = Functional.value("Hello")
    .on(s -> s.length() > 3)
    .as(String::toUpperCase)
    .value();

// Example 2: Conditional side effect
Functional.value(42)
    .on(n -> n > 40)
    .apply(n -> System.out.println("Value is: " + n));

// Example 3: Named functional operation
Functional.of("user", user)
    .on(u -> u.isActive())
    .as(User::getName)
    .apply(name -> System.out.println("Active user: " + name));

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.util.Functional;

API Reference

Public Methods

Method Description
on
as
apply
value
value
of
of

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally