Skip to content

Instantly share code, notes, and snippets.

View JavierCane's full-sized avatar
🤟
Working on @CodelyTV

Javier Ferrer González JavierCane

🤟
Working on @CodelyTV
View GitHub Profile
@JavierCane
JavierCane / CaseClassCapabilitiesSpec.scala
Created November 22, 2017 10:21
Scala Case Class capabilities test example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
// Full repo: https://github.com/CodelyTV/scala-intro-examples/
package tv.codely.scala_intro_examples.lesson_09_oop
import org.scalatest.{Matchers, WordSpec}
/**
* In order to check all the capabilities that a case class have, just:
* * Compile it with: `scalac`
* * Inspect it with: `javap -private`
*
@JavierCane
JavierCane / StandardClassVisibilitiesSpec.scala
Created November 22, 2017 10:03
Scala standard class visibilities example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
// Full repo: https://github.com/CodelyTV/scala-intro-examples/
package tv.codely.scala_intro_examples.lesson_09_oop
import org.scalatest.{Matchers, WordSpec}
final class StandardClassVisibilitiesSpec extends WordSpec with Matchers {
private val randomText = "some text"
private val standardClass = new StandardClass(attributeInConstruct = randomText)
"Standard Class" should {
@JavierCane
JavierCane / NumberWithCompanionObject.scala
Created November 22, 2017 10:00
Scala companion object example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
package tv.codely.scala_intro_examples.lesson_09_oop
import scala.util.Random
object NumberWithCompanionObject {
def apply(value: String): NumberWithCompanionObject = NumberWithCompanionObject(value = value.toInt)
def random: NumberWithCompanionObject = NumberWithCompanionObject(value = Random.nextInt())
}
@JavierCane
JavierCane / CaseClass.scala
Created November 22, 2017 10:00
Scala case class example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
package tv.codely.scala_intro_examples.lesson_09_oop
final case class CaseClass(
attributeInConstruct: String,
private val privateAttributeInConstruct: String = "Some default value"
) {
val attributeInBody = "public body attribute value"
private val privateAttributeInBody = "private body attribute value"
}
@JavierCane
JavierCane / StandardClass.scala
Created November 22, 2017 10:00
Scala standard class example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
package tv.codely.scala_intro_examples.lesson_09_oop
final class StandardClass(
val attributeInConstruct: String,
private val privateAttributeInConstruct: String = "Some default value"
) {
val attributeInBody = "public body attribute value"
private val privateAttributeInBody = "private body attribute value"
}
package tv.codely.cqrs_ddd_scala_example.acceptance
import java.util.UUID
import scala.reflect.classTag
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import cats.implicits._
import org.joda.time.DateTime
@JavierCane
JavierCane / CurryingExample.scala
Created October 23, 2017 07:43
Currying example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
def sum(a: Int)(b: Int): Int = a+ b
def add1(b:Int) = sum(1)(b)
def add2(b:Int) = sum(2)(b)
def add3(b:Int) = sum(3)(b)
val add4 = sum(4)(_)
add2(5)
add4(6)
@JavierCane
JavierCane / higherOrderFunctions.scala
Created October 23, 2017 07:38
Scala higher order functions example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
def print(
value: String,
printer: String => Unit
): Unit = printer(value)
def printlnPrinter(value: String): Unit = println(value)
val printlnPrinterVal = (value: String) => println(value)
print("Playing with higher order functions", printlnPrinter)
print("Same with functions stored in values", printlnPrinterVal)
@JavierCane
JavierCane / flatMapVsFor.scala
Created October 16, 2017 06:53
Scala Future flatMap vs for comprehension CodelyTV Pro Scala course example
package tv.codely.scala_intro_examples.lesson_05_ifs_for
import scala.concurrent.{ExecutionContext, Future}
final class SandwichMaker(private val fridge: Fridge, private val fryer: Fryer)(implicit ec: ExecutionContext) {
def make(): Future[Sandwich] = {
val breadOptionFuture = fridge.takeBread()
val cheeseOptionFuture = fridge.takeCheese()
val hamOptionFuture = fridge.takeHam()
val eggOptionFuture = fridge.takeEgg()
@JavierCane
JavierCane / SimpleFor.scala
Created October 16, 2017 06:28
Scala for examples for the CodelyTV Pro Scala course
val lele = if ("Codely mola".isInstanceOf[String]) 3 else 7
var total = 0
for (value <- 1 to 10) {
total = total + value
println(value)
}
(1 to 10).foreach(value2 => {
println(value2)