Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ramda
javascript
haskell

What is functional programming?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Functional programming is a programming paradigm where the focus is on changing data through small expressions that don’t have side effects.

In other words, when multiples calls to any function occur with the same arguments, the result will always be the same. This is because the functions don’t depend on a local or global state, which produces different results depending on the state.

Functional programming is based on:

First class functions

Functions that can be treated like regular variables. Such functions can be passed as arguments to other functions, can be returned by other functions, and can be assigned as values to a variable.

svg viewer
var foo = function(){
  return "Edpressos are fun!";
}

function Edpresso(greeting){
   console.log("Educative's " + greeting());
}

Edpresso(foo);

Higher order functions

Functions that return other functions are called higher order functions.

svg viewer

Data immutability

Data cannot be modified after creation in functional programming. So for example, an object ‘n’ with the value of 5 will always have the value of 5.

Lazy evaluation

The evaluation of an expression in functional programming is delayed until the value is needed.

// Not lazy
var sum = 1 + 1;
// Evaluates 1 + 1 immediately

// Lazy
const lazySum = () => 1 + 1;
// Evaluates 1 + 1 upon invocation

Recursion

Most functional code is written with recursion instead of for-loops. In fact, some functional languages don’t even support for-loops!

Pure functions

Pure functions are functions whose return values are solely determined by the function’s inputs.

svg viewer
recursion

RELATED TAGS

ramda
javascript
haskell
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring