This file contains 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
class BootLoader extends Bootable { | |
def boot = { | |
LiftRules.exceptionHandler.prepend { | |
case (_, _, throwable) => { | |
val errorReport = ErrorReport( | |
throwable, | |
Authenticater.userRequestVar.is.get.username) | |
TopComponentImpl.errorReportService.handleErrorReport(errorReport) | |
InternalServerErrorResponse() | |
} |
This file contains 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
trait Service1Component { | |
val service1: Service1 | |
trait Service1 { | |
def announce(): Unit | |
} | |
} | |
trait Service1ComponentImpl extends Service1Component { | |
override val service1: Service1 = new Service1Impl | |
private class Service1Impl extends Service1 { |
This file contains 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
trait ExampleServiceComponent { | |
val exampleService: ExampleService | |
trait ExampleService | |
} | |
trait ExampleServiceComponentImpl extends ExampleServiceComponent { | |
// why do I have to redeclare the type of exampleService?? | |
override val exampleService: ExampleService = new ExampleServiceImpl |
This file contains 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
sealed trait Maybe[+A] { | |
// >>= | |
def flatMap[B](f: A => Maybe[B]): Maybe[B] | |
} | |
case class Just[+A](a: A) extends Maybe[A] { | |
override def flatMap[B](f: A => Maybe[B]) = f(a) | |
} |
This file contains 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
sealed trait Maybe[+A] { | |
// >>= | |
def flatMap[B](f: A => Maybe[B]): Maybe[B] = this match { | |
case Just(a) => f(a) | |
case MaybeNot => MaybeNot | |
} | |
} |
This file contains 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
object Person { | |
val persons = List("P", "MP", "MMP", "FMP", "FP", "MFP", "FFP") map { Person(_) } | |
private val mothers = Map( | |
Person("P") -> Person("MP"), | |
Person("MP") -> Person("MMP"), | |
Person("FP") -> Person("MFP")) | |
private val fathers = Map( |
This file contains 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 maternalGrandfather(p: Person): Maybe[Person] = | |
p.mother flatMap { _.father } | |
def maternalGrandfatherNoFlatMap(p: Person): Maybe[Person] = | |
p.mother match { | |
case Just(m) => m.father | |
case MaybeNot => MaybeNot | |
} | |
Person.persons foreach { p => |
This file contains 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 bothGrandfathersFlatMap(p: Person): Maybe[(Person, Person)] = | |
p.mother flatMap { m => | |
m.father flatMap { fm => | |
p.father flatMap { f => | |
f.father flatMap { ff => | |
Just(fm, ff) | |
} | |
} | |
} | |
} |
This file contains 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 bothGrandfathersNoFlatMapNoPairMatch(p: Person): Maybe[(Person, Person)] = | |
p.mother match { | |
case Just(m) => | |
p.father match { | |
case Just(f) => | |
m.father match { | |
case Just(fm) => | |
f.father match { | |
case Just(ff) => Just((fm, ff)) | |
case _ => MaybeNot |
This file contains 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
sealed trait Maybe[+A] { | |
// >>= | |
def flatMap[B](f: A => Maybe[B]): Maybe[B] | |
// >> | |
def map[B](f: A => B): Maybe[B] = flatMap { a => Just(f(a)) } | |
} |