Lazy evaluation, Higher-order functions, and Currying
Table Of Contents
· A. lazy evaluation
· B. Higher-order functions and Currying
A. lazy evaluation
Lazy evaluation can be defined as an approach that delays the value of an expression until it’s needed (tutorialspoint, n.d) the primary purpose of using lazy evaluation is to gain more performance, taking Python programming language for instance; lazy evaluation was one of the many things that were improved in Python3, for example, a simple code like following:
in Python2 the output would be: <type ‘list’>
in Python3 the output is: <class ‘range’>
So the type of the variable test shows that in Python3 it holds a range instead of a list, and that’s because lazy evaluation was applied to some built-in functions in Python like range, an alternative in Python2 is xrange which also supports lazy evaluation.
B. Higher-order functions and Currying
Higher-order functions are functions that take another function as an argument or create another function, while currying is when a function takes the first argument and then returns another function until all arguments are fulfilled (geeksforgeeks, 2018)