Skip to content

Instantly share code, notes, and snippets.

@Daenyth
Created January 14, 2022 14:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daenyth/03889157b1c409196c17d8d8e509e603 to your computer and use it in GitHub Desktop.
Save Daenyth/03889157b1c409196c17d8d8e509e603 to your computer and use it in GitHub Desktop.
cats-effect prelude
// ...
lazy val prelude = (project in file("prelude"))
.settings(commonSettings)
.settings(
name := "my-application-prelude",
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % V.Fs2,
"org.typelevel" %% "cats-effect" % V.CatsEffect,
"org.typelevel" %% "log4cats-core" % V.Log4Cats,
)
)
// ...
val preludeImport =
scalacOptions ++= Seq("-Yimports:java.lang,scala,scala.Predef,com.myproject.prelude.Prelude")
// ...
lazy val root = (project in file("."))
.settings(preludeImport)
.dependsOn(prelude)
// ...
package com.myproject.prelude
import cats.syntax.{AllSyntaxBinCompat => CatsSyntax}
import cats.effect.syntax.{AllSyntax => CESyntax}
import cats.effect.instances.{AllInstances => CEInstances}
/** Custom prelude for importing with -Yimport
*
* This means we never need to import cats syntax or stream explicitly
*/
object Prelude extends CatsSyntax with CESyntax with CEInstances {
val Stream = fs2.Stream
type Stream[+F[_], +O] = fs2.Stream[F, O]
val IO = cats.effect.IO
type IO[+A] = cats.effect.IO[A]
val Deferred = cats.effect.Deferred
type Deferred[F[_], A] = cats.effect.Deferred[F, A]
val Resource = cats.effect.Resource
type Resource[F[_], +A] = cats.effect.Resource[F, A]
type Sync[F[_]] = cats.effect.Sync[F]
val Sync = cats.effect.Sync
type Async[F[_]] = cats.effect.Async[F]
val Async = cats.effect.Async
type Ref[F[_], A] = cats.effect.Ref[F, A]
val Ref = cats.effect.Ref
type Logger[F[_]] = org.typelevel.log4cats.Logger[F]
val Logger = org.typelevel.log4cats.Logger
type Console[F[_]] = cats.effect.std.Console[F]
val Console = cats.effect.std.Console
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment