This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Reference module with a choice of impure functions. | |
*/ | |
object Impure{ | |
def add(x: Int, y: Int): Int = | |
x + y | |
def impureSum(x: Int, y: Int): Int = { | |
println(s"Beginning addition ...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package object typesafe_builder{ | |
import scala.language.higherKinds | |
// Auxiliary type constructor. It allows us to represent | |
// that an argument has been set. | |
type Id[T] = T | |
// The target domain class | |
case class Person(age: Int, name: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FUNCTIONS */ | |
// Functions as objects | |
val suma2: (Int, Int) => Int = (x: Int, y: Int) => x + y | |
val suma1: Int => Int => Int = x => y => x+ y | |
val suma2: Function2[Int, Int, Int] = (x: Int, y: Int) => x + y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.libs.json._ | |
import play.api.data.validation.ValidationError | |
object Test{ | |
type Tagged[U] = { type Tag = U } | |
trait NonEmpty | |
type NonEmptyString = String with Tagged[NonEmpty] |