All Projects → evolution-gaming → cats-helper

evolution-gaming / cats-helper

Licence: MIT License
Helpers for cats & cats-effect

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to cats-helper

tagless-final-jam
Workshop On Tagless Final Interpreters
Stars: ✭ 37 (+94.74%)
Mutual labels:  cats, tagless-final, cats-effect
tutorials
🎥 Source code of the examples shown in the video tutorials
Stars: ✭ 18 (-5.26%)
Mutual labels:  cats, cats-effect
fs2-ftp
Simple client for Ftp/Ftps/Sftp
Stars: ✭ 24 (+26.32%)
Mutual labels:  cats, cats-effect
pfps-examples
🏮 Standalone examples shown in the book "Practical FP in Scala: A hands-on approach"
Stars: ✭ 167 (+778.95%)
Mutual labels:  cats, cats-effect
tradeio
A disciplined way to purely functional domain models in Scala
Stars: ✭ 19 (+0%)
Mutual labels:  cats, cats-effect
typelevel-stack.g8
📚 Unofficial Giter8 template for the Typelevel Stack (Http4s / Doobie / Circe / Cats Effect / Fs2) based on Cats v1.x.x
Stars: ✭ 63 (+231.58%)
Mutual labels:  cats, cats-effect
zenith
⚡ Functional Scala HTTP server, client, and toolkit.
Stars: ✭ 15 (-21.05%)
Mutual labels:  cats, tagless-final
Monix
Asynchronous, Reactive Programming for Scala and Scala.js.
Stars: ✭ 1,819 (+9473.68%)
Mutual labels:  cats, cats-effect
scala-functional-programming-tutorial
Functional Programming in Scala Tutorial
Stars: ✭ 23 (+21.05%)
Mutual labels:  cats, cats-effect
skafka
Scala wrapper for kafka consumer and producer
Stars: ✭ 35 (+84.21%)
Mutual labels:  cats, cats-effect
console4cats
💻 Effect-type agnostic Console I/O for Cats Effect (archived, use Cats Effect 3 instead)
Stars: ✭ 55 (+189.47%)
Mutual labels:  cats, cats-effect
influencer-stats
Playground for measuring performance of functional programming tools in Scala. Gathers statistics about videos.
Stars: ✭ 24 (+26.32%)
Mutual labels:  cats, cats-effect
spotify-next
Small CLI app for filtering out music on Spotify.
Stars: ✭ 45 (+136.84%)
Mutual labels:  tagless-final, cats-effect
classy-optics
🔎 Source code shown at my talks at Scale by the Bay 2018 and Scalar 2019
Stars: ✭ 25 (+31.58%)
Mutual labels:  cats, cats-effect
cats-effect-testing
Integration between cats-effect and test frameworks
Stars: ✭ 155 (+715.79%)
Mutual labels:  cats, cats-effect
tinyweb
Simple and lightweight HTTP async server for micropython
Stars: ✭ 182 (+857.89%)
Mutual labels:  cats, cats-effect
swam
WebAssembly engine in Scala
Stars: ✭ 38 (+100%)
Mutual labels:  cats, cats-effect
vault4s
Vault Client Library For Scala
Stars: ✭ 15 (-21.05%)
Mutual labels:  cats, cats-effect
fs2-ssh
A wrapper around Apache SSHD targeting cats-effect and fs2
Stars: ✭ 36 (+89.47%)
Mutual labels:  cats, cats-effect
telegramium
Telegramium or F[ Tg ] - pure functional Telegram Bot API implementation for Scala.
Stars: ✭ 42 (+121.05%)
Mutual labels:  cats, cats-effect

Cats Helper

Build Status Coverage Status Codacy Badge Version License: MIT

ClockHelper

import com.evolutiongaming.catshelper.ClockHelper._

val clock = Clock.const[Id](nanos = 1000, millis = 2)

clock.millis // 2
clock.nanos // 1000
clock.micros // 1
clock.instant // Instant.ofEpochMilli(2)

SerialRef

Like Ref but allows A => F[A] rather than A => A
Ensures that updates are run serially

import com.evolutiongaming.catshelper.SerialRef

for {
  ref <- SerialRef.of[IO, Int](0)
  _   <- ref.update(a => (a + 1).pure[IO])
} yield {}

LazyVal

Functional alternative to lazy keyword in Scala

trait LazyVal[F[_], A] {

  def get: F[A]

  def getLoaded: F[Option[A]]
}

ToFuture & FromFuture

trait ToFuture[F[_]] {
  def apply[A](fa: F[A]): Future[A]
}

trait FromFuture[F[_]] {
  def apply[A](future: => Future[A]): F[A]
}

ToTry & FromTry

trait ToTry[F[_]] {

  def apply[A](fa: F[A]): Try[A]
}

trait FromTry[F[_]] {

  def apply[A](fa: Try[A]): F[A]
}

Log

trait Log[F[_]] {

  def debug(msg: => String): F[Unit]

  def info(msg: => String): F[Unit]

  def warn(msg: => String): F[Unit]

  def warn(msg: => String, cause: Throwable): F[Unit]

  def error(msg: => String): F[Unit]

  def error(msg: => String, cause: Throwable): F[Unit]
}

Runtime

trait Runtime[F[_]] {

  def availableCores: F[Int]

  def freeMemory: F[Long]

  def totalMemory: F[Long]

  def maxMemory: F[Long]

  def gc: F[Unit]
}

ThreadLocalRef

trait ThreadLocalRef[F[_], A] {

  def get: F[A]

  def set(a: A): F[Unit]

  def update(f: A => A): F[Unit]

  def modify[B](f: A => (A, B)): F[B]
}

ResourceFenced

This is useful to ensure release called at most once, in cases when "unsafe" api like Resource.allocated being used

val resource: Resource[F, A] = ???
resource.fenced

ReadWriteRef

A mutable reference to A value with read-write lock semantics.

FeatureToggled

Manages a given Resource[F, A] providing access to it only when a feature-toggle is on.

val serviceResource: Resource[F, AService] = ???
val flag: F[Boolean] = ???

val ftService: Resource[F, Resource[F, Option[AService]]] = FeatureToggled
  .polling(
    serviceResource,
    flag,
    pollInterval = 10.seconds,
    gracePeriod = 30.seconds,
  )

ftService.use { access =>
  access.use {
    case Some(service) => service.doStuff(…)
    case None          => F.unit
  }
}

PureTest

This helper lives in a separate cats-helper-testkit module. It is makes testing F[_]-based code easier.

NOTE: cats-helper-testkit is an experimental module and may break SemVer guarantees from time to time. However we will do our best to avoid unnecessary breakages.

"what time is it now?" in PureTest[IO].of { env =>
  import env._
  for {
    _ <- IO.sleep(1.hour)
    _ <- testRuntime.getTimeSinceStart.map(_ shouldBe 1.hour)
  } yield ()
}

Setup

addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")

libraryDependencies += "com.evolutiongaming" %% "cats-helper" % "2.2.3"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].