This file contains hidden or 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
| // Type parameter placeholder: S[_] | |
| def str[T, S[_]](ss: S[T]): String = ss.toString | |
| val s1 = str(Seq(1, 2, 3)) // "List(1, 2, 3)" | |
| // Function parameter placeholder: _.toUpperCase | |
| val loud = Seq("hello world!").map(_.toUpperCase) // List(HELLO WORLD!) | |
| // Match placeholder: _ in the first two case clauses | |
| Seq(Seq('a', 'b', 'c'), Seq(1, 2, 3), Seq(1.1, 2.2)).map { | |
| seq => seq match { |
This file contains hidden or 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 io.circe._ | |
| import io.circe.parser._ | |
| import io.circe.syntax._ | |
| import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} | |
| import akka.http.scaladsl.model.{ContentTypeRange, HttpEntity} | |
| import akka.http.scaladsl.model.MediaTypes.`application/json` | |
| import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller} | |
| import scala.concurrent.Future |
This file contains hidden or 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 io.circe._ | |
| import io.circe.parser._ | |
| import io.circe.syntax._ | |
| import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} | |
| import akka.http.scaladsl.model.{ContentTypeRange, HttpEntity} | |
| import akka.http.scaladsl.model.MediaTypes.`application/json` | |
| import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller} | |
| import scala.concurrent.Future |
This file contains hidden or 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
| abstract class Animal | |
| case class Cat(name: String) extends Animal | |
| case class Dog(name: String, owner: String) extends Animal | |
| def checkAnimal(animal: Animal): String = { | |
| animal match { | |
| case Cat(name) => "The name of the cat is $name." | |
| case _ => "Its just a dog." |
This file contains hidden or 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
| def sequencesPatternMatching(sequence: Any): String = { | |
| sequence match { | |
| case List(singleElement) => s"I'm a list with one element: $singleElement" | |
| case List(_, _*) => s"I'm a list with one or multiple elements: sequence" | |
| case Vector(1, 2, _*) => s"I'm a vector: $sequence" | |
| case _ => s"I'm an unrecognized sequence. My value: $sequence" | |
| } | |
| } | |
| sequencesPatternMatching(Seq(1,2,3)) |
This file contains hidden or 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 com.joel.akka.streams | |
| import akka.actor.ActorSystem | |
| import akka.stream.scaladsl._ | |
| import akka.Done | |
| import scala.concurrent._ | |
| object Main { |
This file contains hidden or 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 com.joel.akka.streams | |
| import akka.actor.ActorSystem | |
| import akka.stream.scaladsl._ | |
| import akka.Done | |
| import scala.concurrent._ | |
| object Main { |
This file contains hidden or 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 scala.collection.immutable.HashMap | |
| object InstanceOf { | |
| /** | |
| * Investigation of the compile and runtime behaviour of the cast operation asInstanceOf of Scala. | |
| * | |
| * @param args | |
| */ | |
| def main(args: Array[String]): Unit = { |
This file contains hidden or 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 io.circe.Json.Null | |
| import io.circe.{Encoder, Json, ObjectEncoder} | |
| import io.circe.generic.auto._ | |
| import io.circe.generic.semiauto.deriveEncoder | |
| import io.circe.syntax._ | |
| object example { | |
| def main(args: Array[String]) { |
This file contains hidden or 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 java.util.Optional | |
| import scala.jdk.javaapi.OptionConverters | |
| object example { | |
| case class ExampleClassD(e: Int) | |
| case class ExampleClassC(d: Optional[Int]) |