Play Framework FAQ: How do I set the Play Framework 2.6 port in production mode?
You set the port that your Play Framework application listens on by passing the
http.port parameter to the “run” script for your application:
Here’s an example of a command I use to execute the run script for a Play Framework application named myapp:
Problem: You want to define a Scala method that takes a function as a parameter, and that function may have one or more input parameters, and may also return a value.
Solution: Following the approach described in the previous recipe, define a method that takes a function as a parameter. Specify the function signature you expect to receive, and then execute that function inside the body of the method.
In today’s installation of “how to have fun with Scala,” if you want to define a method that takes a parameter that has a generic type, and want to further declare that the parameter must extend some base type, use this syntax:
def getName[A <: RequiredBaseType](a: A) = ???
That example says, “The parameter
a has the generic type
A must be a subtype of
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 19.8, “Examples of how to use types in your Scala classes.”
To put what you’ve learned in this chapter to use, let’s create two examples. First, you’ll create a “timer” that looks like a control structure and works like the Unix time com‐ mand. Second, you’ll create another control structure that works like the Scala 2.10 Try/ Success/Failure classes.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 19.6, “How to define a collection whose element are all of some base type.”Back to top
You want to specify that a class or method takes a type parameter, and that parameter is limited so it can only be a base type, or a subtype of that base type.Back to top
Define the class or method by specifying the type parameter with an upper bound. To demonstrate this, create a simple type hierarchy:Back to top
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 19.2, “How to write a Scala method that takes a simple generic type.”
You’re not concerned about type variance, and want to create a Scala method (or function) that takes a generic type, such as a method that accepts a
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 17.5, “How to annotate varargs methods in Scala.”
You’ve created a Scala method with a varargs field, and would like to be able to call that method from Java code.
When a Scala method has a field that takes a variable number of arguments, mark it with the
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.2, “How to create a Scala/Akka Actor whose constructor requires arguments.”
You want to create an Akka actor, and you want your actor’s constructor to have one or more arguments.
Create the actor using the syntax shown here, where
HelloActor takes one constructor parameter:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.7, “How to create methods that take variable-arguments (varargs) fields.”
To make a method more flexible, you want to define a method parameter that can take a variable number of arguments, i.e., a varargs field.
Define a varargs field in your method declaration by adding a
* character after the field type: