Giter Club home page Giter Club logo

bfect's Introduction

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._

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.