Laziness and Functional Programming

less than 1 minute read

  • As Polymorphism is to object-oriented Programming
  • Lazy Evaluation is to functional programming

https://docs.vavr.io/#_introduction

David Wheeler: In CS we can solve almost any problem by introducing one more level of indirection

  • In procedural code, pointers have given the power of indirection -> instead of compile time, runtime
  • In OO code, overriding functions have given the power of indirection
  • In FP, lambdas give the power of indirection

Thus, Lambdas can give a way to deferring evaluation, postpone evaluation

myFunction1(Type value) - eager
myFunction2(Supplier<Type> supplier) - lazy

When do we pass value vs. a functional interface to a method?

One consideration is lazy evaluation, if there is a need to post poning the implementation