All Projects → tmccarthy → bfect

tmccarthy / bfect

Licence: Apache-2.0 license
Some bifunctor IO type classes

Programming Languages

scala
5932 projects
shell
77523 projects

Projects that are alternatives of or similar to bfect

classy-optics
🔎 Source code shown at my talks at Scale by the Bay 2018 and Scalar 2019
Stars: ✭ 25 (+31.58%)
Mutual labels:  cats, zio
http4s-poc-api
POC: http4s http api on zio
Stars: ✭ 34 (+78.95%)
Mutual labels:  cats, zio
free-arrow
Implementation of the Free Arrow in Scala and other helpful tools for working with Arrows
Stars: ✭ 14 (-26.32%)
Mutual labels:  cats, zio
tutorials
🎥 Source code of the examples shown in the video tutorials
Stars: ✭ 18 (-5.26%)
Mutual labels:  cats, zio
blockchain-rpc
JSON RPC client for Bitcoin, Ethereum and Omni
Stars: ✭ 26 (+36.84%)
Mutual labels:  cats
pfps-examples
🏮 Standalone examples shown in the book "Practical FP in Scala: A hands-on approach"
Stars: ✭ 167 (+778.95%)
Mutual labels:  cats
tamer
Standalone alternatives to Kafka Connect Connectors
Stars: ✭ 42 (+121.05%)
Mutual labels:  zio
tinyweb
Simple and lightweight HTTP async server for micropython
Stars: ✭ 182 (+857.89%)
Mutual labels:  cats
skafka
Scala wrapper for kafka consumer and producer
Stars: ✭ 35 (+84.21%)
Mutual labels:  cats
catmoji-colr
Twemoji, but with cats! Unicode 13.1! 🐱
Stars: ✭ 41 (+115.79%)
Mutual labels:  cats
AUXify
Introduces macro/meta annotations @ aux, @ self, @ instance, @ apply, @ delegated, @ syntax and String-based type class LabelledGeneric
Stars: ✭ 25 (+31.58%)
Mutual labels:  typeclass
freecli
Command line parsing library using Free Applicative
Stars: ✭ 29 (+52.63%)
Mutual labels:  cats
scala-functional-programming-tutorial
Functional Programming in Scala Tutorial
Stars: ✭ 23 (+21.05%)
Mutual labels:  cats
catsay
🐱 💻 like cowsay but cats
Stars: ✭ 33 (+73.68%)
Mutual labels:  cats
gnome-runcat
😼 The cat tells you the CPU usage by running speed
Stars: ✭ 194 (+921.05%)
Mutual labels:  cats
zio-nio
A small, unopinionated ZIO interface to NIO.
Stars: ✭ 177 (+831.58%)
Mutual labels:  zio
tagless-final-jam
Workshop On Tagless Final Interpreters
Stars: ✭ 37 (+94.74%)
Mutual labels:  cats
adversaria
Typeclass interfaces to access user-defined Scala annotations
Stars: ✭ 22 (+15.79%)
Mutual labels:  typeclass
code-examples-manager
Software tool to manage your notes and code examples, to publish them as gists or snippets
Stars: ✭ 26 (+36.84%)
Mutual labels:  zio
Cat-Face-Detector-with-OpenCV-and-JavaFX
📹 A Small OpenCV (Open Source Computer Vision) Example, who has the ability to detect multiple cat faces at the same time 🐱
Stars: ✭ 24 (+26.32%)
Mutual labels:  cats

CircleCI Maven Central

Bfect

A collection of bifunctor effect typeclasses, with instances for ZIO and conversions for cats-effect.

Project structure

  • bfect-core - A collection of bifunctor effect typeclasses, based loosely around the structure of cats-effect
  • bfect-testing - An implementation of a bifunctor state monad along with instances for the bfect-core typeclasses
  • bfect-interop-cats - Implicit conversions between the bfect-core typeclasses and their analogs in cats-core and cats-effect
  • bfect-interop-fs2 - Utilities for interoperation with fs2
  • bfect-interop-zio - Instances of the bfect-core typeclasses for the ZIO IO monad
  • bfect-io - A half-finished bifunctor IO monad (don't use this)

Each of these are available through Maven Central, just add them to your project with your favourite build tool.

Typeclasses

Typeclass Cats equivalent Comment
Bifunctor (BFunctor) cats.Functor/cats.Bifunctor Functor with biMap and its derivations (map/rightMap, leftMap)
BifunctorMonad (BMonad) cats.Monad Monad. Adds flatMap, rightPure and leftPure.
BifunctorMonadError (BME) cats.MonadError Represents the ability to handle errors with handleErrorWith. Comes with the alias BME.
effects.Bracket cats.effect.Bracket Bracket. Represents the pure equivalent of try/finally
effects.Now cats.effect.Timer Represents the ability to create a timestamp
effects.Timer cats.effect.Timer Extends Now with the ability to delay execution for a period of time
effects.Die Extends BifunctorMonadError with the ability to suspend an effect that fails in an unchecked manner
effects.Sync cats.effect.Sync Extends Die with the ability to suspend arbitrary synchronous effects
effects.Async cats.effect.Async Extends Sync with the ability to register asynchronous effects
effects.Concurrent cats.effect.Concurrent Represents the effect of starting and cancelling tasks
effects.extra.Console Represents the effect of writing to the console
effects.extra.EnvVars Represents the effect of accessing environment variables
effects.extra.Resources Represents the effect of accessing Java resources
effects.extra.Calendar Extends Now with the ability to determine the system timezone, enabling computation of the local date and so on.

Note that unlike in cats, Bracket and Concurrent are not part of the main inheritance chain that includes Sync and Async

Usage

Use the following imports:

  • import au.id.tmm.bfect.syntax.all._ for extension methods
  • import au.id.tmm.bfect.instances.all._ for instances
  • import au.id.tmm.bfect.implicits._ for everything
import au.id.tmm.bfect.effects.Sync
import au.id.tmm.bfect.implicits._

// Companion objects provide static methods:

def hello1[F[_, _] : Sync]: F[Nothing, String] = Sync[F].pure("hello")
def hello2[F[_, _] : Sync]: F[Nothing, String] = Sync.pure("hello")

def print1[F[_, _] : Sync](string: String): F[Nothing, Unit] = Sync[F].sync(println(string))
def print2[F[_, _] : Sync](string: String): F[Nothing, Unit] = Sync.sync(println(string))

// Sync.Ops provides instance methods. The following are equivalent:

def printHello1[F[_, _] : Sync]: F[Nothing, Unit] = Sync[F].flatMap(hello1)(print1)
def printHello2[F[_, _] : Sync]: F[Nothing, Unit] = hello1.flatMap(print1)

// Importing Sync.Ops enables for-yield syntax:

def printHello3[F[_, _] : Sync]: F[Nothing, Unit] =
  for {
    hello <- hello1
    _     <- print1(hello)
  } yield ()

Cats interoperation

The bfect-interop-cats package provides implicits for interoperation with Cats. This includes instances for effect types using EitherT. The easiest way to access these is with the following import:

import au.id.tmm.bfect.interop.cats.implicits._
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].