Last active
December 27, 2019 22:11
-
-
Save afsalthaj/de0593e7aafb886ebfebff4fd624eae3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import scalaz.Free | |
sealed trait Notification[A] | |
case class SendEmail(s: String) extends Notification[Unit] | |
case class SendMessage(s: String) extends Notification[Unit] | |
case class NothingJustLog(s: String) extends Notification[Unit] | |
sealed trait Table[Unit] | |
object Table { | |
type TableAction[A] = Free[Table, A] | |
def read(s: String): TableAction[String] = | |
Free.liftF(ReadOp(s)) | |
def write(s: String): TableAction[String] = | |
Free.liftF(WriteOp(s)) | |
def readAndSendNotification(s: String): Free[Table, Notification[Unit]] = | |
for { | |
s <- read(s) | |
notification = if (s == "admin") SendEmail("admin") else SendMessage("admin") | |
} yield notification | |
def writeAndSendNotification(s: String): Free[Table, Notification[Unit]] = | |
for { | |
s <- write(s) | |
notification = if (s == "bla") SendEmail("bla") else SendEmail("admin") | |
} yield notification | |
case class WriteOp(s: String) extends Table[String] | |
case class ReadOp(s: String) extends Table[String] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed the typo of Unit :)