-
Notifications
You must be signed in to change notification settings - Fork 557
Open
Description
I would like to be able to initialize Random
in a different effect, as it's in Ref
and Deffered
(def in[F, G, A]
). Motivation:
- I can't use transformer implicits, because I want to initialize
Random
, for example, inConnectionIO
(type fromDoobie
, which has implementation ofSync
forConnectionIO
). - I don't want to use
mapK
because it would be incorrect and expensive for implementation (ex: provided by libmapK
forConnectionIO
uses aDispatcher
that runs the logic, which adds additional costs for lift and unlift fromIO
)
Below is a sample code for Ref
, I would like to be able to do exactly the same for Random
and SecureRandom
.
import cats.FlatMap
import cats.effect.std.Console
import cats.effect.{Ref, Sync}
import cats.syntax.all.*
class Foo[F[_]: FlatMap: Console](ref: Ref[F, Int]) {
def print: F[Unit] = ref.get.flatMap(Console[F].println)
}
def foo[I[_]: Sync, F[_]: Sync: Console]: I[Foo[F]] =
for {
ref <- Ref.in[I, F, Int](0)
/// Init some classes in F
} yield new Foo(ref)
Proposal:
I looked at current implementation javaSecuritySecureRandom
, and it can be divided into 2 effects. So, new method will have signature like this:
// Proposal - add new method
def javaSecuritySecureRandomIn[I[_]: Sync, F[_]: Sync](n: Int): I[SecureRandom[F]]
// Current impl
def javaSecuritySecureRandom[F[_]: Sync](n: Int): F[SecureRandom[F]]
Metadata
Metadata
Assignees
Labels
No labels