• Not able to find any whitepaper for this. Functional programming (FP) is an approach to software development that uses pure functions to create maintainable software. In other words, building programs by applying and composing functions.

History

Functional Programming is based on Lambda Calculus: 
Lambda calculus is a framework developed by Alonzo Church to study computations with functions. It can be called as the smallest programming language in the world. It gives the definition of what is computable. Anything that can be computed by lambda calculus is computable. It is equivalent to Turing machine in its ability to compute. It provides a theoretical framework for describing functions and their evaluation. It forms the basis of almost all current functional programming languages. 
Fact: Alan Turing was a student of Alonzo Church who created Turing machine which laid the foundation of imperative programming style.

6. Functional Programming concepts implemented in rxjs

  1. Observables: Observables in RxJS represent streams of data over time. They are similar to collections in functional programming and can be treated as first-class entities. Observables can be transformed, combined, and manipulated using various operators, allowing for functional-style data processing.
  2. Higher-Order Functions: RxJS provides numerous higher-order functions, such as map, filter, reduce, mergeMap, and concatMap. These functions take other functions as arguments and operate on the data emitted by the observables. They enable transforming, filtering, aggregating, and composing observables in a functional way.
  3. Function Composition: RxJS facilitates function composition through its operator chaining syntax. Operators can be combined together to form complex data processing pipelines, similar to function composition in functional programming. This allows for a declarative and modular approach to working with asynchronous data streams.
  4. Immutability: While not enforced by RxJS itself, the principles of immutability are often applied when working with observables. Data transformations in RxJS typically create new observables rather than modifying existing ones. This ensures that data remains immutable and reduces the risk of unintended side effects.
  5. Lazy Evaluation: RxJS employs lazy evaluation, meaning that observables only produce values when there are active subscribers. This lazy evaluation strategy aligns with functional programming principles and allows for efficient handling of asynchronous data streams.
  6. Error Handling with Monads: RxJS leverages the concept of monads, such as the catchError operator, to handle errors in a functional style. Monadic error handling allows for a more declarative and composable way to handle and propagate errors within an observable stream.

Key concepts

  1. Pure Functions: Pure functions are functions that always produce the same output for the same input and have no side effects. They don’t modify data outside their scope or rely on external state. Pure functions promote predictability, testability, and composability.
  2. Immutability: Functional programming encourages immutability, which means that once a data structure or value is created, it cannot be modified. Instead, new values are created when transformations or modifications are required. This avoids unintended side effects and makes reasoning about code easier.
  3. Higher-Order Functions: In functional programming, functions are treated as first-class citizens. This means that functions can be assigned to variables, passed as arguments to other functions, and returned as results from functions. Higher-order functions are functions that either take other functions as arguments or return functions.
  4. Function Composition: Functional programming promotes composing functions to create more complex behavior. Function composition involves chaining or combining multiple functions together to create a new function. It allows for modular and reusable code.
  5. Recursion: Recursion is a technique where a function calls itself to solve a problem. Functional programming often relies on recursion instead of iterative loops. Recursive functions break down complex problems into simpler subproblems, which can lead to elegant and concise code.
  6. Immutable Data Structures: Functional programming favors immutable data structures, such as lists, sets, and maps, that don’t change after creation. Instead of modifying these data structures, functional programming encourages creating new instances with modifications. Immutable data structures provide safety and make it easier to reason about program behavior.
  7. Referential Transparency: Referential transparency means that a function can be replaced with its resulting value without changing the program’s behavior. It enables reasoning about code by allowing expressions to be evaluated independently of their context.

Advantages of Functional Programming

  • Modularity – As previously mentioned, functional programming is highly modular. This makes the resulting code shorter and easier to read. Anyone who has tried to decipher monolithic code would appreciate the simplicity. 
  • You can implement lambda calculus in the program – You can use this to solve complex problems. 
  • Contains many functional constructs – These include lazy map, lazy evaluation, and lists.
  • Some programming languages support nested functions – This significantly improves the maintainability of the code.
  • Problems are easier to pinpoint and solve – FP’s reliance on pure functions makes debugging and unit testing easier. Pure functions also prevent confusing issues and errors from developing in the code.
  • Keeps concurrency safe – Code is thread-safe when no two concurrent processes try to access the same data simultaneously. This bug is a race condition. Since pure functions never share a state with other sections of the program, race conditions can’t occur.