Skip to content

Functional Programming

surendrabisht edited this page Jul 16, 2020 · 1 revision

Functional Programming

Functional programming is a style of programming that (as the name suggests) is based around functions.
A key part of functional programming is higher-order functions. We have seen this idea briefly in the previous lesson on functions as objects. Higher-order functions take other functions as arguments, or return them as results.
Functional programming seeks to use pure functions.
Pure functions have no side effects, and return a value that depends only on their arguments.

Pure Functions

Pure function is a function which:

  1. Given the same inputs, always returns the same output, and
  2. Has no side-effects

  • easier to reason about and test.
  • more efficient. Once the function has been evaluated for an input, the result can be stored and referred to the next time the function of that input is needed, reducing the number of times the function is called. This is called memoization.
  • easier to run in parallel.
Clone this wiki locally