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
case class ConnectMessage(deviceId: Long) | |
case object DisconnectMessage | |
case object VolumeAdjustmentMessage | |
case object PauseMessage | |
class BluetoothHeadphones extends Actor { | |
def receive = { | |
case ConnectMessage(message) => | |
case DisconnectMessage => | |
case VolumeAdjustmentMessage => |
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
sealed abstract class Action extends Product with Serializable | |
object Camera { | |
final case class Picture(iso: Int, aperture: Double) extends Action | |
final case class Video (duration: Int) extends Action | |
} | |
def actionHandler(action: Action): Unit = action match { | |
case Camera.Picture(iso, app) => print(s"Took photo with iso: $iso and aperture $app") | |
case Camera.Video(dur) => print(s"Took video for $dur seconds") |
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
case class Watch(mechanism: String) | |
val swissWatch = Watch("swiss") | |
println(swissWatch) | |
// Watch(swiss) |
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
case class Album(title: String, year: Int) | |
val bitusa = Album("Born in the USA", 1980) | |
val bitusaRemaster = Album.copy(year = 1991) |
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
case class Player(name: String) | |
val biggie = Player("Biggie") | |
biggie.name = "2pac" | |
// error: reassignment to val |
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
case class Drink(name: String) | |
val henny = Drink("henny") | |
val henny2 = henny.copy() | |
println(henny.equals(henny2)) | |
//true |
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
sealed trait Topping | |
case object RefriedBeans extends Topping | |
case object Onions extends Topping | |
case object Lettuce extends Topping | |
case object Salsa extends Topping | |
sealed trait Shell | |
case object CornTortilla extends Shell | |
case object TortillaChips extends Shell | |
case object FlourTortilla extends Shell |
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
// from https://blog.codecentric.de/en/2016/07/spark-2-0-datasets-case-classes/ | |
final case class Body(id: Int, | |
width: Double, | |
height: Double, | |
depth: Double, | |
material: String, | |
color: String) | |
val ds = df.as[Body] |
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
// From https://github.com/spray/spray-json | |
case class Color(name: String, red: Int, green: Int, blue: Int) | |
object MyJsonProtocol extends DefaultJsonProtocol { | |
implicit val colorFormat = jsonFormat4(Color) | |
} | |
import MyJsonProtocol._ | |
import spray.json._ |
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
case class Player(firstName: String, lastName: String, ppg: Double, apg: Double, rpg: Double) | |
val jf = Player.apply("Jimmer", "Fredette", 1.1, 0.1, 0.2) | |
print(jf) | |
// Player(Jimmer,Fredette,1.1,0.1,0.2) |
NewerOlder