Type members
Classlikes
Deprecated operations, described as extension methods.
Deprecated operations, described as extension methods.
The Eager
type represents a strict, already evaluated result
of a Coeval that either resulted in success, wrapped in a
Now, or in an error, wrapped in an Error.
The Eager
type represents a strict, already evaluated result
of a Coeval that either resulted in success, wrapped in a
Now, or in an error, wrapped in an Error.
It's the moral equivalent of scala.util.Try
, except that
application of functions such as map
and flatMap
produces
Coeval references that are still lazily evaluated.
- Companion:
- object
Value members
Concrete methods
Promote a non-strict value representing a Coeval
to a Coeval
of the same type.
Promote a non-strict value representing a Coeval
to a Coeval
of the same type.
Promote a non-strict value to a Coeval
, catching exceptions in the
process.
Promote a non-strict value to a Coeval
, catching exceptions in the
process.
Note that since Coeval
is not memoized, this will recompute the
value each time the Coeval
is executed.
Promote a non-strict value to a Coeval
that is memoized on the first
evaluation, the result being then available on subsequent evaluations.
Promote a non-strict value to a Coeval
that is memoized on the first
evaluation, the result being then available on subsequent evaluations.
Guarantees thread-safe idempotency.
'''UNSAFE''' — this operation allocates a shared, mutable reference, which can break in certain cases referential transparency, even if this operation guarantees idempotency (i.e. referential transparency implies idempotency, but idempotency does not imply referential transparency).
The allocation of a mutable reference is known to be a
side effect, thus breaking referential transparency,
even if calling this method does not trigger the evaluation
of side effects suspended by the source.
Use with care. Sometimes it's easier to just keep a shared,
memoized reference to some connection, but keep in mind
it might be better to pass such a reference around as
a parameter.
Converts any value that has a CoevalLike instance into a Coeval
.
Converts any value that has a CoevalLike instance into a Coeval
.
Returns a F ~> Coeval
(FunctionK
) for transforming any
supported data-type into Coeval.
Returns a F ~> Coeval
(FunctionK
) for transforming any
supported data-type into Coeval.
Useful for mapK
transformations, for example when working
with Resource
or Iterant
:
import cats.effect._
import monix.eval._
import java.io._
def open(file: File) =
Resource[SyncIO, InputStream](SyncIO {
val in = new FileInputStream(file)
(in, SyncIO(in.close()))
})
// Lifting to a Resource of Coeval
val res: Resource[Coeval, InputStream] =
open(new File("sample")).mapK(Coeval.liftFrom[SyncIO])
See cats.arrow.FunctionK.
Generates Coeval ~> F
(FunctionK
) values for converting from Coeval
to supporting types (for which we have a CoevalLift instance).
Generates Coeval ~> F
(FunctionK
) values for converting from Coeval
to supporting types (for which we have a CoevalLift instance).
See the documentation.
import cats.effect._
import monix.eval._
import java.io._
def open(file: File) =
Resource[Coeval, InputStream](Coeval {
val in = new FileInputStream(file)
(in, Coeval(in.close()))
})
// Lifting to a Resource of Task
val res: Resource[Task, InputStream] =
open(new File("sample")).mapK(Coeval.liftTo[Task])
// This was needed in order to process the resource
// with a Task, instead of a Coeval
res.use { in =>
Task {
in.read()
}
}
Generates Coeval ~> F
function values (FunctionK
) for converting
from Coeval
to types for which we have a cats.effect.Sync
instance.
Generates Coeval ~> F
function values (FunctionK
) for converting
from Coeval
to types for which we have a cats.effect.Sync
instance.
- See also:
cats.effect.Sync Prefer to use liftTo, this alternative is provided in order to force the usage of
cats.effect.Sync
, since CoevalLift is lawless.
Pairs 2 Coeval
values, applying the given mapping function.
Pairs 2 Coeval
values, applying the given mapping function.
Returns a new Coeval
reference that completes with the result
of mapping that function to their successful results, or in
failure in case either of them fails.
val fa1 = Coeval(1)
val fa2 = Coeval(2)
// Yields Success(3)
Coeval.map2(fa1, fa2) { (a, b) =>
a + b
}
// Yields Failure(e), because the second arg is a failure
Coeval.map2(fa1, Coeval.raiseError[Int](new RuntimeException("boo"))) { (a, b) =>
a + b
}
Pairs 3 Coeval
values, applying the given mapping function.
Pairs 3 Coeval
values, applying the given mapping function.
Returns a new Coeval
reference that completes with the result
of mapping that function to their successful results, or in
failure in case either of them fails.
val fa1 = Coeval(1)
val fa2 = Coeval(2)
val fa3 = Coeval(3)
// Yields Success(6)
Coeval.map3(fa1, fa2, fa3) { (a, b, c) =>
a + b + c
}
// Yields Failure(e), because the second arg is a failure
Coeval.map3(fa1, Coeval.raiseError[Int](new RuntimeException("boo")), fa3) { (a, b, c) =>
a + b + c
}
Pairs 4 Coeval
values, applying the given mapping function.
Pairs 4 Coeval
values, applying the given mapping function.
Returns a new Coeval
reference that completes with the result
of mapping that function to their successful results, or in
failure in case either of them fails.
val fa1 = Coeval(1)
val fa2 = Coeval(2)
val fa3 = Coeval(3)
val fa4 = Coeval(4)
// Yields Success(10)
Coeval.map4(fa1, fa2, fa3, fa4) { (a, b, c, d) =>
a + b + c + d
}
// Yields Failure(e), because the second arg is a failure
Coeval.map4(fa1, Coeval.raiseError[Int](new RuntimeException("boo")), fa3, fa4) {
(a, b, c, d) => a + b + c + d
}
Pairs 5 Coeval
values, applying the given mapping function.
Pairs 5 Coeval
values, applying the given mapping function.
Returns a new Coeval
reference that completes with the result
of mapping that function to their successful results, or in
failure in case either of them fails.
val fa1 = Coeval(1)
val fa2 = Coeval(2)
val fa3 = Coeval(3)
val fa4 = Coeval(4)
val fa5 = Coeval(5)
// Yields Success(15)
Coeval.map5(fa1, fa2, fa3, fa4, fa5) { (a, b, c, d, e) =>
a + b + c + d + e
}
// Yields Failure(e), because the second arg is a failure
Coeval.map5(fa1, Coeval.raiseError[Int](new RuntimeException("boo")), fa3, fa4, fa5) {
(a, b, c, d, e) => a + b + c + d + e
}
Pairs 6 Coeval
values, applying the given mapping function.
Pairs 6 Coeval
values, applying the given mapping function.
Returns a new Coeval
reference that completes with the result
of mapping that function to their successful results, or in
failure in case either of them fails.
val fa1 = Coeval(1)
val fa2 = Coeval(2)
val fa3 = Coeval(3)
val fa4 = Coeval(4)
val fa5 = Coeval(5)
val fa6 = Coeval(6)
// Yields Success(21)
Coeval.map6(fa1, fa2, fa3, fa4, fa5, fa6) { (a, b, c, d, e, f) =>
a + b + c + d + e + f
}
// Yields Failure(e), because the second arg is a failure
Coeval.map6(fa1, Coeval.raiseError[Int](new RuntimeException("boo")), fa3, fa4, fa5, fa6) {
(a, b, c, d, e, f) => a + b + c + d + e + f
}
Returns a Coeval
that on execution is always successful, emitting
the given strict value.
Returns a Coeval
that on execution is always successful, emitting
the given strict value.
Returns a Coeval
that on execution is always finishing in error
emitting the specified exception.
Returns a Coeval
that on execution is always finishing in error
emitting the specified exception.
Returns raiseError
when cond
is false, otherwise Coeval.unit
Returns raiseError
when cond
is false, otherwise Coeval.unit
- Example:
val tooMany = 5 val x: Int = ??? Coeval.raiseUnless(x < tooMany)(new IllegalArgumentException("Too many"))
Returns raiseError
when the cond
is true, otherwise Coeval.unit
Returns raiseError
when the cond
is true, otherwise Coeval.unit
- Example:
val tooMany = 5 val x: Int = ??? Coeval.raiseWhen(x >= tooMany)(new IllegalArgumentException("Too many"))
Transforms a Iterable
of coevals into a coeval producing
the same collection of gathered results.
Transforms a Iterable
of coevals into a coeval producing
the same collection of gathered results.
It's a simple version of traverse.
Keeps calling f
until it returns a Right
result.
Keeps calling f
until it returns a Right
result.
Based on Phil Freeman's Stack Safety for Free.
Transforms a Iterable[A]
into a coeval of the same collection
using the provided function A => Coeval[B]
.
Transforms a Iterable[A]
into a coeval of the same collection
using the provided function A => Coeval[B]
.
It's a generalized version of sequence.
Returns the given argument if cond
is false, otherwise Coeval.Unit
Returns the given argument if cond
is false, otherwise Coeval.Unit
- See also:
Coeval.when for the inverse
Coeval.raiseWhen for conditionally raising an error
Returns the given argument if cond
is true, otherwise Coeval.Unit
Returns the given argument if cond
is true, otherwise Coeval.Unit
- See also:
Coeval.unless for the inverse
Coeval.raiseWhen for conditionally raising an error
Deprecated and Inherited methods
DEPRECATED — please switch to Coeval.from.
DEPRECATED — please switch to Coeval.from.
- Deprecated
[Since version 3.0.0-RC3]
- Inherited from:
- CoevalDeprecatedCompanion
DEPRECATED — please switch to Coeval.from.
DEPRECATED — please switch to Coeval.from.
- Deprecated
[Since version 3.0.0-RC3]
- Inherited from:
- CoevalDeprecatedCompanion
Implicits
Implicits
Deprecated operations, described as extension methods.
Deprecated operations, described as extension methods.
Given an A
type that has a cats.Monoid[A]
implementation,
then this provides the evidence that Coeval[A]
also has
a Monoid[Coeval[A]]
implementation.
Given an A
type that has a cats.Monoid[A]
implementation,
then this provides the evidence that Coeval[A]
also has
a Monoid[Coeval[A]]
implementation.
Instance of Cats type classes for Coeval, implementing
cats.effect.SyncEffect
(which implies Applicative
, Monad
, MonadError
, Sync
)
and cats.CoflatMap
.
Instance of Cats type classes for Coeval, implementing
cats.effect.SyncEffect
(which implies Applicative
, Monad
, MonadError
, Sync
)
and cats.CoflatMap
.
Inherited implicits
Given an A
type that has a cats.Semigroup[A]
implementation,
then this provides the evidence that Coeval[A]
also has
a Semigroup[Coeval[A]]
implementation.
Given an A
type that has a cats.Semigroup[A]
implementation,
then this provides the evidence that Coeval[A]
also has
a Semigroup[Coeval[A]]
implementation.
This has a lower-level priority than Coeval.catsMonoid in order to avoid conflicts.
- Inherited from:
- CoevalInstancesLevel0