Skip to content

Instantly share code, notes, and snippets.

@Klasu
Klasu / DbTransactionMonad.scala
Last active October 14, 2016 07:03
Monad for Database Transactions
// Simple monad to deal with multiple database transactions with same connection, their commits and rollbacks
// Something similar done in http://advorkovyy.blogspot.com.au/2010/10/transactional-monad-for-scala.html
import java.sql.Connection
trait DbTransaction[A] {
def unit: Connection => A
def map[B](f: A => B): DbTransaction[B] = DbTransaction {
connection => f(unit(connection))
}
@Klasu
Klasu / CompileErrorSpec.scala
Last active August 29, 2015 14:05
Scala 2.10 compiler crashes on the following code
import org.specs2.mutable.Specification
case class A(id: Int, created: String)
case class B(id: Int, aId: Int)
case class C(id: Int, created: String)
object ACreator {
val a = A(
id = 1,
created = "A"