When a function returns Unit
it is totally side-effecting. There’s nothing useful that can be done with Unit
, so the function can only perform side effects on some state, either globally, like performing input or output (I/O), or locally in some object.
Normally in functional programming, we prefer pure functions that have no side effects and return all their work as their return value. These functions are far easier to reason about, test, and reuse. Side effects are a common source of bugs.
Ref