0
Functional Programming - Python
I understand how functional programming works but... In which situations can this system be useful? I can't imagine a real life problem where lambda functions are needed. Thanks u all 4 help!!
1 Answer
+ 5
Lambda functions are not used because they are needed!
When you are going to use a function only in a specific piece of code once or twice and is just a few lines it makes sense to use them. You can simply execute the function body where you define it without needing to name it.
//JS code
// anonymous arrow function
(x=> x * x)(2) // 4
//named arrow function
let sq = x => x * x
sq(3) // 9
Expressing code with functional programming is also clean & elegant compared to something like imperative programming.
# some reads below for perspective
http://wiki.c2.com/?AdvantagesOfFunctionalProgramming
https://en.m.wikipedia.org/wiki/Functional_programming