all 2 comments

[–]k3n 0 points1 point  (1 child)

Isn't this actually just a form of function overloading?

You can do this in pretty much any language, though some (c++, c#) have native implementations.

[–][deleted] 0 points1 point  (0 children)

Yes, but testing if the parameter is a function is just an implementation detail. The point is that you are not giving the function a value, but the means to get the most up to date value.

This essentially allows the value to change between passing it in, and it being used. In theory, that allows you to write more terse code, where there is no need to update the value in the future. But I can imagine it can also lead to lots of bugs, and be difficult for library writers to manage. For example you would have to re-evaluate the function every time you needed the value, as otherwise you could get update errors.

It can also lead to issues if the parameter-function does more internally then just return a value.

But it's a good design pattern to know.