I am taking course Functional Programming Principles in Scala | Coursera on Scala.
I fail to understand with immutability , so many functions and so much dependencies on recursion , how is Scala is really suitable for real world applications.
I mean coming from imperative languages I see a risk of StackOverflow or Garbage Collection kicking in and with multiple copies of everything I am running Out Of Memory
What I a missing here?
@tailrecfromscala.annotation.tailrecto make sure your function is 100% tail recursive. This is basically a loop.elem :: listall data is shared between 2 lists - awesome! Only head is created and pointed to the list. Imagine that you have to create a new deep clone of a list every time client asks for.varinside of a function as long as no other code can be affected in any way, i.e. results are always the same.Option[T]and compare tonull. Use them inforcomprehensions. Exception becomes really exceptional andOption, Try, Box, Eithercommunicate failures in a very nice way.