Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala return type

Tags:

scala

I have this as a return type in Scala

 Map[String, Seq[Map[String, Seq[MyClass]]]]

I have to use this in multiple places in my code, is there a way to assign this to a constant of sorts and use the constant instead of explicitly stating it?

like image 881
Bob Avatar asked Jun 19 '12 21:06

Bob


People also ask

What is the return type of function in Scala?

A Scala function definition has the following form −. Syntax def functionName ([list of parameters]) : [return type] = { function body return [expr] } Here, return type could be any valid Scala data type and list of parameters will be a list of

How do you declare a function in Scala?

A Scala function declaration has the following form − def functionName ([list of parameters]) : [return type] Methods are implicitly declared abstract if you don’t use the equals sign and the method body.

Why is the return keyword optional in Scala?

But in Scala, the return keyword is optional, as the Scala compiler treats the value of the last execution within a function as the return value so that we can rewrite our function: Now, why are we discouraged from using the return keyword in Scala if it behaves the same way as in Java and has the same semantics?

How to return a vector from a list in Scala?

We can also return a complete container such as an array, list, or vector. The function returns a vector after looping and yielding in the code below. In Scala, the final expression is assumed to be the return value if there is no return value. If the last expression is what you want to return, you can skip the return keyword.


1 Answers

Yes, you can define a type alias with type Foo = Map[...].

like image 54
drexin Avatar answered Sep 28 '22 04:09

drexin