Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lambda functions vs functors [closed]

when I am going through the lambda function, I have seen people comparing lambda with functors & I came across a statement
users don't have to clutter their code with small functors in some accessible scope.

My doubt is

  1. what is the problem in having small functors in some accessible scope
  2. isn't it good idea to have a single function (functor actually) & reuse it across multiple files in our project.

Thanks.

like image 417
NDestiny Avatar asked May 03 '26 20:05

NDestiny


1 Answers

  1. it is unnecessary if you have to use each only once. Lambdas usually makes the code more readable, the function is defined exactly at the place it is needed.
  2. this is not always the case, a function may be called at only one place. Of course if you needed it at different places a functor may be more appropriate.
like image 130
Jean-Baptiste Yunès Avatar answered May 06 '26 09:05

Jean-Baptiste Yunès