Scala tasks and questions
In this topic, I will collect different questions and small tasks of Scala.
Solutions or explanations will be on any page. All related by # - numbers.
#1. Why method generates an error at compile time:
error: missing parameter type for expanded function
<console>:11: error: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: Int
def recursiveSum(xs :Int*) :Int = {
^
For example, you write a method like this, to calculate sum recursively.
#2. How to make a chain of PartialFunctions, manually and with fold, and use it to filter data.
And the short explanation about P.F. and their methods.
Solutions or explanations will be on any page. All related by # - numbers.
#1. Why method generates an error at compile time:
error: missing parameter type for expanded function
<console>:11: error: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: Int
def recursiveSum(xs :Int*) :Int = {
^
For example, you write a method like this, to calculate sum recursively.
def recursiveSum(xs :Int*) :Int = {
case xs :Seq[Int] if xs.isEmpty => 0
case xs :Seq[Int] if xs.nonEmpty => xs.head + recursiveSum(xs.tail: _*)
}
#2. How to make a chain of PartialFunctions, manually and with fold, and use it to filter data.
And the short explanation about P.F. and their methods.
val resultSeqPers :Seq[Person] = sourceSeqPers collect CombinFilters
,where CombinFilters is a combination of seq of P.F.
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
Комментарии
Отправить комментарий