jam.monad
package jam.monad
Members list
Concise view
Type members
Classlikes
Reval
is a data structure which encodes the idea of allocating an object which has an
associated finalizer. Can be thought of as a mix of cats.effect.Resource
and cats.Eval
.
There are two allocation strategies:
Reval
is a data structure which encodes the idea of allocating an object which has an
associated finalizer. Can be thought of as a mix of cats.effect.Resource
and cats.Eval
.
There are two allocation strategies:
later
: allocates the object once when it is neededalways
: allocates the object every time it is needed
For example:
scala> var c = 0
scala> val a = Reval.thunkLater[IO, Int]{c += 1; c}
scala> a.replicateA(3).map(_.sum).usePure.unsafeRunSync() // List(1, 1, 1).sum
val res0: Int = 3
scala> var c = 0
scala> val a = Reval.thunkAlways[IO, Int]{c += 1; c}
scala> a.replicateA(3).map(_.sum).usePure.unsafeRunSync() // List(1, 2, 3).sum
val res0: Int = 6
Common pitfalls:
later
with multipleuse
calls will allocate later objects for eachuse
scala> var c = 0
scala> val a = Reval.thunkLater[IO, Int] { c += 1; c }
scala> (a.usePure, a.usePure).mapN(_ + _).unsafeRunSync() // 1 + 2
val res1: Int = 3
Attributes
- Companion:
- object
- Graph
- Supertypes
- class Objecttrait Matchableclass Any
- Known subtypes
Attributes
- Companion:
- class
- Graph
- Supertypes
- trait Sumtrait Mirrortrait RevalInstancestrait RevalInstancesLp0class Objecttrait Matchableclass Any
- Self type
- Reval.type