Last active
January 12, 2018 00:01
-
-
Save bpholt/d003e9a24eeca2c963f58e9bba5bbed5 to your computer and use it in GitHub Desktop.
Free Monad Stream
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
name := "example" | |
scalaVersion := "2.12.4" | |
scalacOptions ++= Seq( | |
"-feature", | |
"-deprecation", | |
"-Ypartial-unification", | |
// "-Xlog-implicits", | |
) | |
libraryDependencies ++= { | |
val fs2Version = "0.10.0-RC1" | |
val catsVersion = "1.0.1" | |
Seq( | |
"org.typelevel" %% "cats-free" % catsVersion, | |
"co.fs2" %% "fs2-core" % fs2Version, | |
) | |
} |
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
// Exiting paste mode, now interpreting. | |
<pastie>:39: error: type mismatch; | |
found : fs2.Stream[F,MetricAlarm] | |
required: FreeCloudWatch.this.StreamF[A] | |
(which expands to) fs2.Stream[F,A] | |
case DescribeAlarms() ⇒ Stream.emit(MetricAlarm("my-alarm")).covary[F] |
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
// cats 1.0.1, fs2 0.10.0-RC1 | |
import cats._ | |
import cats.data._ | |
import cats.implicits._ | |
import cats.effect.Effect | |
import cats.free.Free | |
import cats.free.Free.liftF | |
import fs2._ | |
import scala.language.higherKinds | |
case class MetricAlarm(alarmName: String) | |
class FreeCloudWatch[F[_] : Effect] { | |
sealed trait CloudWatchA[A] | |
case class DescribeAlarms() extends CloudWatchA[StreamF[MetricAlarm]] | |
case class DeleteAlarm(alarmNames: StreamF[MetricAlarm]) extends CloudWatchA[Unit] | |
type CloudWatch[A] = Free[CloudWatchA, A] | |
type StreamF[A] = Stream[F, A] | |
def describeAlarms: CloudWatch[StreamF[MetricAlarm]] = | |
liftF[CloudWatchA, StreamF[MetricAlarm]](DescribeAlarms()) | |
def deleteAlarms(alarms: StreamF[MetricAlarm]): CloudWatch[Unit] = | |
liftF[CloudWatchA, Unit](DeleteAlarm(alarms)) | |
def javaSdkCompiler: CloudWatchA ~> StreamF = new (CloudWatchA ~> StreamF) { | |
override def apply[A](fa: CloudWatchA[A]): StreamF[A] = fa match { | |
case DescribeAlarms() ⇒ Stream.emit(MetricAlarm("my-alarm")).covary[F] | |
case DeleteAlarm(_) ⇒ Stream.emit(()).covary[F] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
free.scala:31 should have been
With that change, the gist compiles.