Skip to content

All about Java Functional Programming with Lambda and Streams

Notifications You must be signed in to change notification settings

yuvraj1510/java-functional-programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-functional-programming

Functional programming is a paradigm that allows programming using expressions i.e. declaring functions, passing functions as arguments and using functions as statements.

Implementations using Structural Programming

Implementations using Functional Programming

Using Streams, Filters and Lambdas:

Using Map:

Using Reduce:

Using Distinct and Sorted:

Using Collect:

Using allMatch, noneMatch, anyMatch:

Using Comparator:

Using skip, limit:

Using max, min, findFirst, findAny:

Using sum, average, count:

Using groupingBy:

Using Stream.of, Arrays.stream, IntStream, LongStream, BigInteger:

Using joining, flatMap:

Using parallelStreams:

Terminal or Intermediate operations:

  • Function or method which returns another stream of element called as Intermediate functions or methods or operations. They are Lazy and execute only when terminal operation is executed.
  • Function or method which does not return another stream of element called as Terminal functions or methods or operations.
  • Example

Functional Interfaces:

A functional interface has exactly one abstract method.

  • Predicate<T>: Represents a predicate (boolean-valued function) of one argument.
  • Function<T, R>: Represents a function that accepts one argument and produces a result.
  • Consumer<T>: Represents an operation that accepts a single input argument and returns no result.
  • BinaryOperator<T>: Represents an operation upon two operands of the same type, producing a result of the same type as the operands.
  • Supplier<T>: Represents a supplier of results. It does not take any arguments.
  • UnaryOperatory<T>: Represents an operation on a single operand that produces a result of the same type as its operand.
  • BiPredicate<T, R>: Represents a predicate (boolean-valued function) of two arguments.
  • BiFunction<T, U, R>: Represents a function that accepts two arguments and produces a result.
  • BiConsumer<T, U>: Represents an operation that accepts two input arguments and returns no result.
  • IntBinaryOperator: Represents an operation upon two int-valued operands and producing an int-valued result.
  • IntConsumer: Represents an operation that accepts a single int-valued argument and returns no result.
  • IntFunction<R>: Represents a function that accepts an int-valued argument and produces a result.
  • IntPredicate: Represents a predicate (boolean-valued function) of one int-valued argument.
  • IntSupplier: Represents a supplier of int-valued results.
  • IntToDoubleFunction: Represents a function that accepts an int-valued argument and produces a double-valued result.
  • IntToLongFunction: Represents a function that accepts an int-valued argument and produces a long-valued result.
  • IntUnaryOperator: Represents an operation on a single int-valued operand that produces an int-valued result.

Behavior Parameterization:

Passing the behaviour as parameter or argument to a method is called as Behavior Parameterization.

Method Reference:

Method reference is used to refer method of functional interface. The Method reference can only be used to replace a single method of lambda expression.

Higher Order Functions:

Higher Order Function is a function which returns a function.

Java Made Easy:

Few examples of real time Java problems that made very easy using functional programming

Releases

No releases published

Packages

No packages published

Languages