Imagine you're building an application, and you keep running into a recurring problem: handling complex data and the operations you want to perform on it. Functional programming is a paradigm that can help you tackle this challenge elegantly and efficiently.
Until recently, functional programming felt like mysterious and complicated territory to me due to its strong connection with mathematics. However, I attended a talk by Henar Hernández at autentifront where she explained some functional programming concepts in a simple way. In this article, I'll share what I learned.
Fundamentals of Functional Programming
In functional programming there are a series of important fundamentals or characteristics that should be fulfilled:
Programming must be declarative
In functional programming, declarative programming is emphasized over imperative programming. This means you declare what your application should do, rather than how it should do it, by encapsulating the logic in functions.
Here's an example:
// Imperative code
const listOfNumbers = [1,2,3,4,5,6,7,8,9]
let sumResult = 0
for (let i = 0; i < listOfNumbers.length; i++){
sumResult += listOfNumbers[i]
}