A view to a collection
Databases have views. A database view works just like a table; however, the table never exists. It is just an illusion. A view is only a stored query, which is run when the view name is referenced:
Mysql> CREATE VIEW first_last AS SELECT first_name, last_name FROM NAMES WHERE last_name LIKE ('k%'); mysql> SELECT first_name FROM first_last;
The view first_last
query is backed by the result set of a query, on a real table, NAMES
. We can select only the columns of interest and apply some transformations on them.
Scala collection views are similar. We will soon be giving a close look to functional transformation. However, to get a taste, the following is an example:
We need to assign a temporary password to a user. We have a list of randomly generated passwords. We need to pick one.
Our validation rules are:
A password cannot be empty.
It must have at least an uppercase letter.
It should have a numeric character.
It must have a special character.
It must have five or more...