Skip to content

Instantly share code, notes, and snippets.

> aurelia-skeleton-navigation-webpack@1.1.2 start /home/escala
> npm run server:dev
> aurelia-skeleton-navigation-webpack@1.1.2 server:dev /home/escala
> cross-env NODE_ENV=development npm run webpack-dev-server -- --inline --progress --profile --watch
> aurelia-skeleton-navigation-webpack@1.1.2 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:*",
trait Restaurant {
def menu: String
}
case class Mexican() extends Restaurant {
def menu: String = "tacos"
}
case class Italian() extends Restaurant {
def menu: String = "spaghetti"
type IOEither[A] = EitherT[IO, String, A]
type IOEitherOption[A] = OptionT[IOEither, 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)
trait MonadReader[F[_], E] {
val monad: Monad[F]
def ask: F[E]
def reader[A](f: E => F[A]): F[A]
}
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)
}
}
def program(R: MonadReader[IO, Config]): IO[Unit] = {
for {
status <- R.reader(getJobStatus)
_ <- R.reader(sendAlert(status))
} yield ()
}
sealed trait Status
case object Healthy extends Status
case object Degraded extends Status
case object Unavailable extends Status
case class Env(serverUrl: String)
case class SystemState(value: Map[Env, Status])
def getServerStatus[F[_]](): Env => F[Status] = ???
def alertAdmin[F[_]](status: Status): Env => F[Unit] = ???
final class IndexedReaderWriterStateT[F[_], E, L, SA, SB, A](val runF: F[(E, SA) => F[(L, SB, A)]]) {
def map[B](f: A => B)(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, L, SA, SB, B] = {
transform { (l, s, a) => (l, s, f(a)) }
}
def transform[LL, SC, B](f: (L, SB, A) => (LL, SC, B))
(implicit F: Functor[F]): IndexedReaderWriterStateT[F, E, LL, SA, SC, B] = {
IndexedReaderWriterStateT.applyF {
F.map(runF) { rwsfa =>