Skip to content

Instantly share code, notes, and snippets.


Jowanza Joseph josep2

View GitHub Profile
View message_container.scala
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 =>
View case_class_adt.scala
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")
View print_case_class.scala
case class Watch(mechanism: String)
val swissWatch = Watch("swiss")
// Watch(swiss)
View copy_case_class.scala
case class Album(title: String, year: Int)
val bitusa = Album("Born in the USA", 1980)
val bitusaRemaster = Album.copy(year = 1991)
View case_class_immutable.scala
case class Player(name: String)
val biggie = Player("Biggie") = "2pac"
// error: reassignment to val
View equal.scala
case class Drink(name: String)
val henny = Drink("henny")
val henny2 = henny.copy()
View case_objects.scala
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
View case_class_spark.scala
// from
final case class Body(id: Int,
width: Double,
height: Double,
depth: Double,
material: String,
color: String)
val ds =[Body]
View case_class_spray.scala
// From
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._
View apply_caseclass.scala
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)
// Player(Jimmer,Fredette,1.1,0.1,0.2)