Functional Programming

Mayanktyagi
Nov 4 · 1 min read

Functional programming contains the following key concepts:

  • Functions as first class objects :- JavaScript functions are first-class functions meaning functions and objects are treated as the same thing. Functions can be stored as a variable inside an object or an array as well as it can be passed as an argument or be returned by another function. That makes function “first-class citizens in JavaScript”

First-class citizens- which can be passed as method or function argument

A lambda expression is an inline implementation of a functional interface, eliminating the need of an anonymous class

Every object in Java has a type; the same is true of lambda expressions. The type of a lambda expression is any functional interface for which the lambda expression is an implementation

  • Pure functions

A pure function is a function where the return value is only determined by its input values, without observable side effects

Used to make programming easier

  • Higher order functions :- A function is a higher order function if at least one of the following conditions are met:

The function takes one or more functions as parameters.

The function returns another function as result.

Example

public static void main(String[] args) {

List<Integer> list = new ArrayList<>();

list.add(1);

list.add(2);

list.add(3);

Comparator<Integer> comparator=(String a,Stringb)->{

return a.compareTo(b) };

Collections.sort(list,comparator);}

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade