Side Effect

来源:互联网 发布:云视通网络监控怎么用 编辑:程序博客网 时间:2024/05/16 18:36

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

《Programming Scala》

0 0