Elements of Functional Programming – SCALA
The solution should contain instructions to write out results.
1. Create a 7-element list containing the names of the days of the week. Write it using:
a. Loop of type for
b. The for loop, listing only days with names beginning with "P"
c. Foreach method
d. While loop
e. Recursive function
f. Recursive function by writing elements of the list from the end
g. Foldl and foldr method
h. Foldl methods by writing only days with names beginning with "P"
2. Create a map with product names and prices. On its basis, generate another map with a 10% price reduction. Use the collection mapping mechanism.
3. Define a function accepting a tuple with three values of different types and writing them out
4. Present the Option operation on any example (e.g., a map in which we search for values by key)
5. Use Pattern Matching in a function that accepts a String parameter. For strings corresponding to the names of the days of the week, the function is to return "Work" and "Weekend" (respectively for working and non-working days), for the rest: "There is no such a day".
6. Define the KontoBankowe class with the methods of payment and withdrawal and property Account status - the property is to be read-only. The class should provide a constructor accepting the initial state of the account and another one, setting the initial account balance at 0.
7. Define the class Person with properties: name and surname. Create several instances of this class. Define a function that accepts the object of the person class and selects and returns the string containing the person's greeting by using Pattern Matching. Define 2-3 different greetings for specific people (with given names or surnames) and one default greeting.
8. Write a function that removes zero from the list of integer values (i.e. returning a new list containing values from the original list except for '0')
9. Define a function that accepts a list of integers and returns the list generated based on it, in which all numbers have been increased by 1. Use the collection mapping mechanism.
10. Create a function that accepts a list of real numbers and returns a list created on its basis containing the absolute values of elements from the original list within the range <-5,12>