object Ref extends Serializable
- Source
- Ref.scala
- Alphabetic
- By Inheritance
- Ref
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply[F[_]](implicit mk: Make[F]): ApplyBuilders[F]
Builds a
Refvalue for data types that are SyncBuilds a
Refvalue for data types that are SyncThis builder uses the Partially-Applied Type technique.
Ref[IO].of(10) <-> Ref.of[IO, Int](10)
- See also
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- implicit def catsInvariantForRef[F[_]](implicit arg0: Functor[F]): Invariant[[β$4$]Ref[F, β$4$]]
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def copyOf[F[_], A](source: Ref[F, A])(implicit arg0: Make[F], arg1: FlatMap[F]): F[Ref[F, A]]
Creates a
Refstarting with the value of the one insource.Creates a
Refstarting with the value of the one insource.Updates of either of the Refs will not have an effect on the other (assuming A is immutable).
- def empty[F[_], A](implicit arg0: Make[F], arg1: Monoid[A]): F[Ref[F, A]]
Creates a
Refwith empty content - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def in[F[_], G[_], A](a: A)(implicit F: Sync[F], G: Sync[G]): F[Ref[G, A]]
Builds a
Refvalue for data types that are Sync like of but initializes state using another effect constructor - final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def lens[F[_], A, B](ref: Ref[F, A])(get: (A) => B, set: (A) => (B) => A)(implicit F: Functor[F]): Ref[F, B]
Creates an instance focused on a component of another
Ref's value.Creates an instance focused on a component of another
Ref's value. Delegates every get and modification to underlyingRef, so both instances are always in sync.Example:
case class Foo(bar: String, baz: Int) val refA: Ref[IO, Foo] = ??? val refB: Ref[IO, String] = Ref.lens[IO, Foo, String](refA)(_.bar, (foo: Foo) => (bar: String) => foo.copy(bar = bar))
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def of[F[_], A](a: A)(implicit mk: Make[F]): F[Ref[F, A]]
Creates a thread-safe, concurrent mutable reference initialized to the supplied value.
Creates a thread-safe, concurrent mutable reference initialized to the supplied value.
import cats.effect.IO import cats.effect.kernel.Ref for { intRef <- Ref.of[IO, Int](10) ten <- intRef.get } yield ten
- def ofEffect[F[_], A](fa: F[A])(implicit arg0: Make[F], arg1: FlatMap[F]): F[Ref[F, A]]
Creates a
Refstarting with the result of the effectfa. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unsafe[F[_], A](a: A)(implicit F: Sync[F]): Ref[F, A]
Like
applybut returns the newly allocatedRefdirectly instead of wrapping it inF.delay.Like
applybut returns the newly allocatedRefdirectly instead of wrapping it inF.delay. This method is considered unsafe because it is not referentially transparent -- it allocates mutable state.This method uses the Partially Applied Type Params technique, so only effect type needs to be specified explicitly.
Some care must be taken to preserve referential transparency:
import cats.effect.IO import cats.effect.kernel.Ref class Counter private () { private val count = Ref.unsafe[IO, Int](0) def increment: IO[Unit] = count.update(_ + 1) def total: IO[Int] = count.get } object Counter { def apply(): IO[Counter] = IO(new Counter) }
Such usage is safe, as long as the class constructor is not accessible and the public one suspends creation in IO.
The recommended alternative is accepting a
Ref[F, A]as a parameter:class Counter (count: Ref[IO, Int]) { // same body } object Counter { def apply(): IO[Counter] = Ref[IO](0).map(new Counter(_)) }
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- object Make extends MakeInstances