Skip to content

Instantly share code, notes, and snippets.

@lu4nm3
Last active May 14, 2020 02:07
Show Gist options
  • Save lu4nm3/a54c00566823d978dea3b587b3db1cb3 to your computer and use it in GitHub Desktop.
Save lu4nm3/a54c00566823d978dea3b587b3db1cb3 to your computer and use it in GitHub Desktop.
def program[F[_]](R: MonadReader[F, Env],
W: MonadWriter[F, Vector[SystemState]],
S: MonadState[F, SystemState]): F[(Vector[SystemState], SystemState)] = {
implicit val M: Monad[F] = R.monad
for {
status <- R.reader(getServerStatus[F]())
state <- S.get
env <- R.ask
updatedState = SystemState(state.value + (env -> status))
_ <- S.set(updatedState)
_ <- W.tell(Vector(updatedState))
_ <- status match {
case Degraded | Unavailable => R.reader(alertAdmin[F](status))
case _ => M.unit
}
logs <- W.logs
finalState <- S.get
} yield (logs, finalState)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment