I know that Scala has var
(for mutable state) but pure functional programming discourages use of any mutable state and rather focuses on using val
for everything.
Coming from an imperative world it's hard to let go of mutable state.
My question is when is it okay to use var in your Scala code ? Can all code really be done using just val. If yes, then why does Scala have vars?
Here are some reasons for vars in Scala: