Skip to content

Instantly share code, notes, and snippets.

def createMonadReader[E](value: E): IO[MonadReader[IO, E]] = {
for {
input <- Ref.of[IO, E](value)
} yield new MonadReader[IO, E] {
val monad: Monad[IO] = Monad[IO]
def ask: IO[E] = input.get
def reader[A](f: E => IO[A]): IO[A] = ask.flatMap(f)
}
}
trait MonadReader[F[_], E] {
val monad: Monad[F]
def ask: F[E]
def reader[A](f: E => F[A]): F[A]
}
val getJobStatus: Config => IO[Status] = ???
def sendAlert(status: Status): Config => IO[Unit] = ???
// ReaderT[F[_], E, A] is a type alias of Kleisli[F, E, A] so we can use the Kleisli constructor to wrap our functions
val getJobStatusR: ReaderT[IO, Config, Status] = Kleisli(getJobStatus)
def sendAlertR(status: Status): ReaderT[IO, Config, Unit] = Kleisli(sendEmail(status))
val program: ReaderT[IO, Config, Unit] = for {
status <- getJobStatusR
_ <- sendAlertR(status, user)
type IOEither[A] = EitherT[IO, String, A]
type IOEitherOption[A] = OptionT[IOEither, A]
@lu4nm3
lu4nm3 / main.rs
Last active June 25, 2024 02:44
Tokio Async: Concurrent vs Parallel
use futures::StreamExt;
use std::error::Error;
use tokio;
use tokio::macros::support::Pin;
use tokio::prelude::*;
use tokio::time::{Duration, Instant};
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut multi_threaded_runtime = tokio::runtime::Builder::new()
.threaded_scheduler()
> [email protected] start /home/escala
> npm run server:dev
> [email protected] server:dev /home/escala
> cross-env NODE_ENV=development npm run webpack-dev-server -- --inline --progress --profile --watch
> [email protected] webpack-dev-server /home/escala
> cross-env BABEL_ENV=node ./node_modules/.bin/webpack-dev-server "--inline" "--progress" "--profile" "--watch"
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "autoscaling:Describe*",
"Effect": "Allow",
"Resource": "*"
},
{
"Action": "ec2:*",