Last active
May 14, 2020 02:07
-
-
Save lu4nm3/c204edf91f07c5d52ddd9eb3b6387caa 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
def createMonadWriter[L](implicit M: Monoid[L]): IO[MonadWriter[IO, L]] = { | |
for { | |
writer <- Ref.of[IO, L](M.empty) | |
} yield new MonadWriter[IO, L] { | |
val monad: Monad[IO] = Monad[IO] | |
def tell(l: L): IO[Unit] = writer.update(_.combine(l)) | |
def logs: IO[L] = writer.get | |
} | |
} | |
def createMonadState[S](initial: S): IO[MonadState[IO, S]] = { | |
for { | |
state <- Ref.of[IO, S](initial) | |
} yield new MonadState[IO, S] { | |
val monad: Monad[IO] = Monad[IO] | |
def get: IO[S] = state.get | |
def set(s: S): IO[Unit] = state.set(s) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment