Functional Programming: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 40: Line 40:


{{External|https://docs.oracle.com/javase/10/docs/api/java/util/stream/package-summary.html#Associativity}}
{{External|https://docs.oracle.com/javase/10/docs/api/java/util/stream/package-summary.html#Associativity}}
==Non-Interfering Function==
{{External|https://docs.oracle.com/javase/10/docs/api/java/util/stream/package-summary.html#NonInterference}}


=Closures=
=Closures=

Revision as of 01:20, 29 March 2018

Internal

Overview

The functional programming cornerstones are the ability to pass functions as arguments and no shared mutable data. Functional programming is essentially different than imperative programming, where a program is described in terms of a sequence of statements that mutate state.

Java 8 introduced lambda expressions, which allow behavior parameterization and functional programming.

Closures and recursion are at the base of the functional programming paradigm.

Behavior Parameterization

Behavior parameterization is a software development pattern that facilitates handling frequent requirement changes. It essentially means taking a block of code and making it available to API calls, which will execute it internally, or will pass it, in turn, to other API layers. The block of code can be called later by other parts of the program - its execution is deferred.

Behavior parameterization is similar to the strategy pattern. In this context, "behavior" and "strategy" can be used interchangeably.

Prior to Java 8, behavior parameterization was possible with anonymous classes. In Java 8, functions can be explicitly passed to the API, as parameters, and returned as results.

Function

From an object-oriented programming language perspective, a function is a block of code that receives a list of arguments and that optionally returns a result, and possibly throws an exception. A function is different from a method in that the function is not associated with any particular class.

If a function is associative and stateless, it can be used to implement inherently parallelizable reduction operations.

Pure Function

A piece of behavior that is perfectly descried solely by the way it transform arguments to results, behaving as a mathematical function and having no side effects. Also known as side-effect-free function or stateless function.

Also see Parallelism.

Stateless Function

https://docs.oracle.com/javase/10/docs/api/java/util/stream/package-summary.html#Statelessness

Stateful Function

Associative Function

https://docs.oracle.com/javase/10/docs/api/java/util/stream/package-summary.html#Associativity

Non-Interfering Function

https://docs.oracle.com/javase/10/docs/api/java/util/stream/package-summary.html#NonInterference

Closures

Closures