Skip to content

Instantly share code, notes, and snippets.

Here's how you can add a type variable to not maintain two parallel-but-similar case classes:

case class UserEntityF[F[_]](id: Option[Long] = None, username: F[String], password: F[String])

type Id[A] = A

// You can also just use Option if you don't care
// for the domain-specific type
sealed trait Updatable[+A]
case class Update[A](a :A) extends Updatable[A]

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x