Giter Club home page Giter Club logo

java-functional-programming's Introduction

java-functional-programming

Practice functional programming paradigm’s core principles with Java programming language.

Documentation

For review the documentation you can use:

https://www.baeldung.com/java-functional-programming

Example:

In this example, a Stream is used to process a list of names. The lambda expression name -> name.startsWith("A") is passed to the filter method, which selects only elements that meet the criterion of starting with "A". The result is collected into a new list (namesStartingWithA). This approach reflects the functional nature by treating operations as transformations rather than direct state changes.

import java.util.Arrays;
import java.util.List;

public class FunctionalProgrammingExample {

    public static void main(String[] args) {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "David", "Eve");

        // Using lambda expressions and the filter method to get names starting with "A"
        List<String> namesStartingWithA = names.stream()
                .filter(name -> name.startsWith("A"))
                .collect(java.util.stream.Collectors.toList());

        System.out.println("Names starting with 'A': " + namesStartingWithA);
    }
}

Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state change and mutable variables. Instead of modifying state, it focuses on applying pure functions that produce results based solely on their inputs, without side effects.

Java introduced functional programming features with the release of Java 8 in March 2014. One of the most significant additions was the introduction of lambda expressions and the java.util.function package, which provides pre-defined functional interfaces.

java-functional-programming's People

Contributors

daniepusb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.