Skip to content

cats-effect specific modules can be unified  #28

Description

@Baccata

You can unify both cats-effect-2 and cats-effect-3 modules into a single "cats" module (doesn't actually need cats-effect, and opens the usage to a lot more datatypes than just effect types). Something like :

package avocado.instances

import avocado.AvocADO
import cats.Monad
import cats.Parallel

object cats {
  given [F[_]: Monad Parallel] : AvocADO[F] = new AvocADO[F] {
    def pure[A](a: A): F[A] = Monad[F].pure(a)
    def map[A, B](fa: F[A], f: A => B): F[B] = Monad[F].map(fa)(f)
    def zip[A, B](fa: F[A], fb: F[B]): F[(A, B)] = Parallel.parTuple2(fa, fb)
    def flatMap[A, B](fa: F[A], f: A => F[B]): F[B] = Monad[F].flatMap(fa)(f)
  }
}

This will work for both cats-effect-2 and cats-effect3, and only needs the dependency to cats-core. Moreover, it'll give users access to the ado block in contexts such as Either/Validated, where errors would automatically be aggregated in a data structure.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions