Whenever we want to use a value that is not readily available yet – for example, when we
call a function to compute or fetch something over the network –
we can not be sure if things go as were planned.
What if the database connection is down? What if the user typed in an invalid string?
Looping over a collection of items and transforming the individual elements
within is quite a common task. So it seems natural that Scala offers a nice
way to solve this.
Whenever we want to use a value that is not readily available yet – for example, when we
call a function to compute or fetch something over the network –
we can not be sure if things go as were planned.
What if the database connection is down? What if the user typed in an invalid string?
After Lists and tuples, let’s have a look at Maps.
They are sometimes called “hashtables”, “hashes”, or “dictionaries” in other programming languages.
Maps are a bit more complex than what we’ve seen before. They come handy
when you need to store associated pairs of data, or when
you need to easily look up a value corresponding to another value (which we will call the key).
In the following couple of posts we’ll learn about basic data structures,
and how they can be used in Scala.
Lists are what their name suggests: they can keep a list of things. The order
of its elements will be kept,
and a list does not care if an element appears more than once in it (which means it will not remove duplicates).
This is a more ‘practical’ topic, and I’m sure that many would argue
that learning how to use a unit testing framework is not strictly necessary
for newcomers. But according to my experience, getting into the
habit of writing tests regularly quickly pays off.
Pattern matching is a quite commonly used “programming pattern” in functional languages, because it
fits nicely into the “functional way of thinking”, and it is quite powerful and handy as a tool.
Generally in programming, enumerations (a.k.a. enums)
are light-weight means to create a very simple model within our code, for
representing a custom type with a limited set of possible values with readable
names.
This description might sound a bit too abstract, so
let’s see an example instead.
You’re probably here because you’ve heard that Scala is a cool programming language
and you’d like to learn more about it. Because, hey, it’s object-oriented and functional at the same time!
I’ll show you something very basic at first: a bit more “personal” version
of the famous
“Hello World” program.