Skip to main content

Functional Programming

What is functional Programming?

Another way of programming which is termed as a subset of the declarative programming languages. The declaratinve way's focus is to define what the program has to do or achieve rather how it should do or acheive it.

The basic objective of this style of programming is to make code more concise, less complex, more predictable, and easier to test compared to the legacy style of coding. Functional programming deals with certain key concepts such as pure function, immutable state, assignment-less programming etc.

  • A pure function should return a value based only on the arguments and should have no side effects.
  • Immutable refers to the property that an entity can't be modified after being instantiated.
  • Higher-order functions are capable of receiving functions as arguments and returning a function as a result.

Lambda expressions

A Lambda expression is an anonymous method that has mutability at very minimum and it has only a parameter list and a body. The return type is always inferred based on the context. Also, make a note, Lambda expressions work in parallel with the functional interface. The syntax of a lambda expression is:

(parameter) -> body