Warning: Some posts on this platform may contain adult material intended for mature audiences only. Viewer discretion is advised. By clicking ‘Continue’, you confirm that you are 18 years or older and consent to viewing explicit content.
Pure functions should be referentially transparent; you should be able to replace them with whatever value they evaluate to without changing the semantics of your code.
Throwing is referentially impure: what value do you get from calling x => thrownewRuntimeException()?
Instead, functional languages prefer to return a tagged union of the value or the error.
Pure functions should be referentially transparent; you should be able to replace them with whatever value they evaluate to without changing the semantics of your code.
Throwing is referentially impure: what value do you get from calling
x => throw new RuntimeException()
?Instead, functional languages prefer to return a tagged union of the value or the error.