Packages

object Ref

Source
Ref.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Ref
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. final class ApplyBuilders[F[_]] extends AnyVal
  2. implicit final class RefOps[F[_], A] extends AnyVal

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply[F[_]](implicit F: Sync[F]): ApplyBuilders[F]

    Builds a Ref value for data types that are Sync

    Builds a Ref value for data types that are Sync

    This builder uses the Partially-Applied Type technique.

    Ref[IO].of(10) <-> Ref.of[IO, Int](10)
    See also

    of

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. implicit def catsInvariantForRef[F[_]](implicit arg0: Functor[F]): Invariant[[β$2$]Ref[F, β$2$]]
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  12. def in[F[_], G[_], A](a: A)(implicit F: Sync[F], G: Sync[G]): F[Ref[G, A]]

    Builds a Ref value for data types that are Sync Like of but initializes state using another effect constructor

  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. def lens[F[_], A, B <: AnyRef](ref: Ref[F, A])(get: (A) => B, set: (A) => (B) => A)(implicit F: Sync[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 underlying Ref, 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))
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. def of[F[_], A](a: A)(implicit F: Sync[F]): F[Ref[F, A]]

    Creates an asynchronous, concurrent mutable reference initialized to the supplied value.

    Creates an asynchronous, concurrent mutable reference initialized to the supplied value.

    import cats.effect.IO
    import cats.effect.concurrent.Ref
    
    for {
      intRef <- Ref.of[IO, Int](10)
      ten <- intRef.get
    } yield ten
  19. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. def unsafe[F[_], A](a: A)(implicit F: Sync[F]): Ref[F, A]

    Like apply but returns the newly allocated ref directly instead of wrapping it in F.delay.

    Like apply but returns the newly allocated ref directly instead of wrapping it in F.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.concurrent.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(_))
    }
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  24. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped