Referential Transparency
Learn about referentially transparent functions with different useful examples.
Overview
A referentially transparent function is one in which the function call is interchangeable with the output of the function. This interchangeability shouldn’t affect a program’s side effects or side causes. Like immutability, referential transparency is associable with pure functions. In fact, the latter is a metric for measuring the former.
The lambda function above replaces spaces in a text with underscores. This function’s output, with a "hello world" input, is compared with the underscore-separated string "hello_world". The comparison yields a positive result, implying that this function call could’ve been replaced with the ...