Packages

final class STM[+E, +A] extends AnyVal

STM[E, A] represents an effect that can be performed transactionally, resulting in a failure E or a value A.

def transfer(receiver: TRef[Int],
             sender: TRef[Int], much: Int): UIO[Int] =
  STM.atomically {
    for {
      balance <- sender.get
      _       <- STM.check(balance >= much)
      _       <- receiver.update(_ + much)
      _       <- sender.update(_ - much)
      newAmnt <- receiver.get
    } yield newAmnt
  }

  val action: UIO[Int] =
    for {
      t <- STM.atomically(TRef.make(0).zip(TRef.make(20000)))
      (receiver, sender) = t
      balance <- transfer(receiver, sender, 1000)
    } yield balance

Software Transactional Memory is a technique which allows composition of arbitrary atomic operations. It is the software analog of transactions in database systems.

The API is lifted directly from the Haskell package Control.Concurrent.STM although the implementation does not resemble the Haskell one at all. http://hackage.haskell.org/package/stm-2.5.0.0/docs/Control-Concurrent-STM.html

STM in Haskell was introduced in: Composable memory transactions, by Tim Harris, Simon Marlow, Simon Peyton Jones, and Maurice Herlihy, in ACM Conference on Principles and Practice of Parallel Programming 2005. https://www.microsoft.com/en-us/research/publication/composable-memory-transactions/

See also: Lock Free Data Structures using STMs in Haskell, by Anthony Discolo, Tim Harris, Simon Marlow, Simon Peyton Jones, Satnam Singh) FLOPS 2006: Eighth International Symposium on Functional and Logic Programming, Fuji Susono, JAPAN, April 2006 https://www.microsoft.com/en-us/research/publication/lock-free-data-structures-using-stms-in-haskell/

Self Type
STM[E, A]
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. STM
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def *>[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, B]

    Sequentially zips this value with the specified one, discarding the first element of the tuple.

  4. final def <*[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, A]

    Sequentially zips this value with the specified one, discarding the second element of the tuple.

  5. final def <*>[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, (A, B)]

    Sequentially zips this value with the specified one.

  6. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  7. final def >>=[E1 >: E, B](f: (A) ⇒ STM[E1, B]): STM[E1, B]

    Feeds the value produced by this effect to the specified function, and then runs the returned effect as well to produce its results.

  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. final def collect[B](pf: PartialFunction[A, B]): STM[E, B]

    Simultaneously filters and maps the value produced by this effect.

  10. final def commit: IO[E, A]

    Commits this transaction atomically.

  11. final def const[B](b: ⇒ B): STM[E, B]

    Maps the success value of this effect to the specified constant value.

  12. final def either: STM[Nothing, Either[E, A]]

    Converts the failure channel into an Either.

  13. val exec: (Journal) ⇒ TRez[E, A]
  14. final def filter(f: (A) ⇒ Boolean): STM[E, A]

    Filters the value produced by this effect, retrying the transaction until the predicate returns true for the value.

  15. final def flatMap[E1 >: E, B](f: (A) ⇒ STM[E1, B]): STM[E1, B]

    Feeds the value produced by this effect to the specified function, and then runs the returned effect as well to produce its results.

  16. final def flatten[E1 >: E, B](implicit ev: <:<[A, STM[E1, B]]): STM[E1, B]

    Flattens out a nested STM effect.

  17. final def fold[B](f: (E) ⇒ B, g: (A) ⇒ B): STM[Nothing, B]

    Folds over the STM effect, handling both failure and success, but not retry.

  18. final def foldM[E1, B](f: (E) ⇒ STM[E1, B], g: (A) ⇒ STM[E1, B]): STM[E1, B]

    Effectfully folds over the STM effect, handling both failure and success.

  19. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  20. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  21. final def map[B](f: (A) ⇒ B): STM[E, B]

    Maps the value produced by the effect.

  22. final def mapError[E1](f: (E) ⇒ E1): STM[E1, A]

    Maps from one error type to another.

  23. final def option: STM[Nothing, Option[A]]

    Converts the failure channel into an Option.

  24. final def orElse[E1, A1 >: A](that: ⇒ STM[E1, A1]): STM[E1, A1]

    Tries this effect first, and if it fails, tries the other effect.

  25. final def orElseEither[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, Either[A, B]]

    Returns a transactional effect that will produce the value of this effect in left side, unless it fails, in which case, it will produce the value of the specified effect in right side.

  26. def toString(): String
    Definition Classes
    Any
  27. final def unit: STM[E, Unit]

    Maps the success value of this effect to unit.

  28. final def withFilter(f: (A) ⇒ Boolean): STM[E, A]

    Same as filter

  29. final def zip[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, (A, B)]

    Named alias for <*>.

  30. final def zipLeft[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, A]

    Named alias for <*.

  31. final def zipRight[E1 >: E, B](that: ⇒ STM[E1, B]): STM[E1, B]

    Named alias for *>.

  32. final def zipWith[E1 >: E, B, C](that: ⇒ STM[E1, B])(f: (A, B) ⇒ C): STM[E1, C]

    Sequentially zips this value with the specified one, combining the values using the specified combiner function.

Deprecated Value Members

  1. final def void: STM[E, Unit]

    Maps the success value of this effect to unit.

    Maps the success value of this effect to unit.

    Annotations
    @deprecated
    Deprecated

    (Since version 1.0.0) use unit

Inherited from AnyVal

Inherited from Any

Ungrouped