cps

package cps

Type members

Classlikes

trait AsyncShift[T]

AsynsShift is a marker base trait for typeclass, which provides 'shifted' variants of the hight-order methods of T, which called when we need to pass a cps-transformed function as an argument for this method.

AsynsShift is a marker base trait for typeclass, which provides 'shifted' variants of the hight-order methods of T, which called when we need to pass a cps-transformed function as an argument for this method.

The general convention is next:

  • Let us have object O and method m(f: A=>B):R which accept hight-order argument f: A=>B. (for example - map in List).
  • If we want to defined transformation of argument for any monad F, we should define the AsyncShift[O] with method m[F[_],...](o:O, m:CpsMonad[F])(f: A=>F[B]).
  • Return type of this method can be F[R] or R or AsyncSubst[R].

Also we should define a given instance of AsyncShift[O], visible from our async block. I.e. implementation for our list will look as:

   class MyShiftedList[T] extentds AsyncShift[List[T]] {

     def map[F[_],S](m:CpsMonad[M], c:List[T])(f: T=>F[S]): F[List[T]] =
         ... // implementation here

   }

   transparent inline given myShiftedList[T]: AsyncShift[List[T]] = MyShiftedList[T]()

After this, you can freely use awaits inside "List.map":

  async {
    ....
    val fetched = uris.map(uri => await(fetch(uri)))
    ...
  }

see https://rssh.github.io/dotty-cps-async/HighOrderFunctions.html

Companion
object
Source
AsyncShift.scala
class AwaitValueDiscard[F[_], T] extends ValueDiscard[F[T]]

Marker interface for forcing monad evaluation before discard. Useful for pure effect monads.

Marker interface for forcing monad evaluation before discard. Useful for pure effect monads.

Source
ValueDiscard.scala
trait CpsAsyncEffectMonad[F[_]] extends CpsAsyncMonad[F] with CpsEffectMonad[F]

Async Effect Monad

Async Effect Monad

Source
CpsMonad.scala
trait CpsAsyncMonad[F[_]] extends CpsTryMonad[F]

Monad, which is compatible with passing data via callbacks.

Monad, which is compatible with passing data via callbacks.

Interoperability with Future: allows

   async[F]{ .. await[Future](..) ... }
Source
CpsMonad.scala
trait CpsAwaitable[F[_]]

Marker typeclass for wrappers, which we can await. Such traits can be not monads itself (for example, its impossible to set monad structure over js.Promise) but can be convertable into cps monads.

Marker typeclass for wrappers, which we can await. Such traits can be not monads itself (for example, its impossible to set monad structure over js.Promise) but can be convertable into cps monads.

Source
CpsMonad.scala

Marker trait for concurrent effect monads.

Marker trait for concurrent effect monads.

Source
CpsMonad.scala
trait CpsConcurrentMonad[F[_]] extends CpsAsyncMonad[F]

Monad, where we can define an effect of starting operation in different execution flow.

Monad, where we can define an effect of starting operation in different execution flow.

Source
CpsMonad.scala
trait CpsEffectMonad[F[_]] extends CpsMonad[F]

Marker trait, which mark effect monad, where actual evaluation of expression happens after building a monad, during effect evaluation stage.

Marker trait, which mark effect monad, where actual evaluation of expression happens after building a monad, during effect evaluation stage.

evaluation of expression inside async block always delayed.

Source
CpsMonad.scala
trait CpsMonad[F[_]] extends CpsAwaitable[F]

Basic CpsMonad operations. Implementing this typeclass is enough to use async/await with supports of basic control-flow constructions (if, loops, but no exceptions).

Basic CpsMonad operations. Implementing this typeclass is enough to use async/await with supports of basic control-flow constructions (if, loops, but no exceptions).

Source
CpsMonad.scala
trait CpsSchedulingMonad[F[_]] extends CpsConcurrentMonad[F]

Monad, where we can spawn some event and be sure that one be evaluated, event if we drop result.

Monad, where we can spawn some event and be sure that one be evaluated, event if we drop result.

Interoperability with Future: allows

  async[Future]{
     ...
     await[F](..)
     ...
  }
Source
CpsMonad.scala
trait CpsTryMonad[F[_]] extends CpsMonad[F]

If you monad supports this typeclass, than you can use try/catch/finally inside await.

If you monad supports this typeclass, than you can use try/catch/finally inside await.

Source
CpsMonad.scala
trait ValueDiscard[T]

When cps.customValueDiscard is on, value can be discarded only for types T for which exists ValueDiscard[T]

When cps.customValueDiscard is on, value can be discarded only for types T for which exists ValueDiscard[T]

see chapter in User Guide

Companion
object
Source
ValueDiscard.scala

Value members

Concrete methods

inline def async[F[_]](using inline am: CpsMonad[F]): InferAsyncArg[F]
@compileTimeOnly("await should be inside async block")
def await[F[_], T](f: F[T])(using am: CpsAwaitable[F]): T