Hi all, I am currently trying izumi-fundamentals, I have something like this
import izumi.functional.bio.{BIOMonadError, F}
case class MyClass[F[+_, +_]: BIOMonadError](){
F.fail("Some Error")
}
From looking at the izumi BIO page, I am lead to believe the code above should give me back an F
however I am getting back a ZIO.
Is there something I may be missing here? There is no ZIO imports in scope
BIOAsync
provides race
& parTraverse
@neko-kai thanks for the info. I am trying to basically achieve a zipPar
I currently have the following simple/naive implementation
def zip2Par[F[+_, +_]: BIOFork: BIOMonadError, E, A0, A1](
a: F[E, A0],
b: F[E, A1]
): F[E, (A0, A1)] =
for {
f0 <- a.fork
f1 <- b.fork
j0 <- f0.join.catchAll ( e =>
f1.interrupt *> BIOMonadError[F].fail(e)
)
j1 <- f1.join
} yield (j0, j1)
Is this functionality something that already exists in BIO
?
@Adriani277 Assuming you’re inheriting a new class BIOCatsParallel
from BIOCatsSync
, where:
class BIOCatsSync[F[+_, +_]](override val F: BIO[F]) extends BIOCatsBracket[F](F) with cats.effect.Sync[F[Throwable, ?]]
Then the Monad[M] is fulfilled by this
– override val monad: Monad[F[Throwable, ?]] = this
The Parallel.applicative
field is the parallel applicative - aka an applicative where zip is implemented by zipPar. So you’d override type F[A] = F[Throwable, A]
and implement the applicative inline:
override lazy val applicative: Applicative[F] = new Applicative[F] {
def zip = zipPar
def traverse = parTraverse
def ap = ...
}
M
and some kind of parallel variant of M, F
. In this case the parallel variant is the same type, we just use different functions to implement the parallel applicative.
cats.Parallel
I have come across an issue which I am not sure what the best way to resolve it is
BeforeAndAfterAll
, where I can have access to the injected Resources
? override protected def config: TestConfig = {
super.config.copy(
memoizationRoots = Set(DIKey.get[PgSvcExample]),
...
That's how you declare a dependency to be shared across all the tests
PgSvcExample
may be a resource, in that case it would be created before all the tests and finalized after all the tests
We need more customized integration checks than what’s provided by the ResourceCheck
trait: https://github.com/7mind/distage-livecode/blob/livecode/src/main/scala/livecode/code.scala#L186
We have something as follows: https://github.com/BlueBrain/nexus/blob/master/cli/src/test/scala/ch/epfl/bluebrain/nexus/cli/postgres/AbstractPostgresSpec.scala#L45
DIResource
with acquire/release actions that are your before/afterAll actions. Then you can pin the resource to be global via memoizationRoots
AND pin the resource to be a dependency of all tests such that it doesn’t need to be summoned manually as a parameter for its acquire/release actions to execute.final class MyTransactor[F[_]] extends DIResourceBase[F, MyTransactor[F]] {
def acquire = waitForPostgres
def release = deleteAllTables
}
trait MyTest extends DistageAbstractScalatestSpec[IO] {
override def config = super.config.copy(
memoizationRoots = super.config.memoizationRoots ++ Set(
DIKey.get[MyTransactor[F]], // force MyTransactor to be acquired/released only once per test-run
),
forcedRoots = super.config.forcedRoots ++ Set(
DIKey.get[MyTransactor[F]], // force MyTransactor to be acquired/released always, no matter if the running tests declare it as a parameter
)
)
}
make[Transactor[IO]].fromEffect(...)
) and for the waiting logic I need the transactor itselfprivate def waitForPostgresReady(xa: Transactor[IO], maxDelay: FiniteDuration = 30.seconds): IO[Unit] = ???
reuse=true
allows reusing the same container between multiple test runs on top of that