Skip to content

Commit

Permalink
add apply for algebras.
Browse files Browse the repository at this point in the history
  • Loading branch information
khajavi committed Jan 12, 2020
1 parent 060b1c5 commit 8867e2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/scala/com/speakfreely/tasbih/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ object Main extends CatsApp {

private implicit def logger[F[_]](implicit sync: Sync[F]): BlockLogger[F] = BlockLogger[F]

private def sampleProgram[F[_]](B: BaseBlockChain[F],
L: Logger[F])(implicit F: Monad[F]): F[Unit] = {
import B._
import L._
private def sampleProgram[F[_]: Logger: BaseBlockChain: Monad]: F[Unit] = {
val L = Logger[F]
val B = BaseBlockChain[F]
import L._, B._

for {
_ <- addBlock("Hello")
_ <- addBlock("Block")
Expand All @@ -32,5 +33,5 @@ object Main extends CatsApp {
}

override def run(args: List[String]): ZIO[Console, Nothing, Int] =
sampleProgram[Task](blockChain, logger).fold(_ => 1, _ => 0)
sampleProgram[Task].fold(_ => 1, _ => 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ trait BaseBlockChain[F[_]] {

}

object BaseBlockChain {
def apply[F[_]](implicit F: BaseBlockChain[F]): BaseBlockChain[F] = F
}

case class Block(index: Int,
previousHash: String,
timestamp: Long,
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/speakfreely/tasbih/algebras/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ import scala.language.higherKinds
trait Logger[F[_]] {
def log(string: String): F[Unit]
}

object Logger {
def apply[F[_]](implicit F: Logger[F]): Logger[F] = F
}

0 comments on commit 8867e2e

Please sign in to comment.