Skip to content

Instantly share code, notes, and snippets.

View jserranohidalgo's full-sized avatar

Juan Manuel Serrano jserranohidalgo

View GitHub Profile
@jserranohidalgo
jserranohidalgo / logging.scala
Last active September 22, 2015 14:43
Step-by-step definition of logging programs
/*
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 ...")
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)
@jserranohidalgo
jserranohidalgo / malagascala.scala
Last active August 29, 2015 14:23
The essence of purely functional programming: removing side effects
/* 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
@jserranohidalgo
jserranohidalgo / gist:0c5c9998f581f26c1150
Last active September 29, 2017 18:10
Exploit tagged types to add constraints on standard values, with custom Json deserializers
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]