You have imperative code that breaks referential transparency.
Wrap the imperative code with
IO, which can be referenced safely without, and save the side effects for the last, outermost layer of your program.
This file is literate Scala, and can be run using Codedown:
$ curl https://earldouglas.com/posts/itof/side-effects-to-io.md | codedown scala | xargs -0 scala -nc -e 6 * 7 = 42 6 * 7 = 42 6 * 7 = 42 6 * 7 = 42