PatchStreamT

object PatchStreamT extends LowPriority0
trait LowPriority0
class Object
trait Matchable
class Any

Type members

Classlikes

object Patch
Companion
class
sealed
trait Patch[+A]
Companion
object

Types

opaque type Snapshot[A]

A scalaz.FingerTree representing the snapshot of the sequence at a certain time.

A scalaz.FingerTree representing the snapshot of the sequence at a certain time.

Note

The measurement of this scalaz.FingerTree is the size.

Value members

Concrete methods

def apply[M[_], A]: CovariantStreamT[M, Patch[A]] =:= PatchStreamT[M, A]
def fromCovariantStreamT[M[_], A](stream: CovariantStreamT[M, A])(using Functor[M]): PatchStreamT[M, A]
def fromIterable[M[_], A](iterable: Iterable[A])(using Applicative[M]): PatchStreamT[M, A]

Givens

Givens

given Monad_PatchStreamT[M[_]](using val M: Nondeterminism[M]): Monad[[X] =>> PatchStreamT[M, X]]
given OneStep_Iterable_PatchStreamT: Lift[From, To]
given StackSafe_Keyword_PatchStreamT_Value: StackSafe[Keyword, PatchStreamT[M, Element], Value]

Inherited givens

given OneStep_From_PatchStreamT: Lift[From, To]
Inherited from
LowPriority0

Extensions

Extensions

extension [M[_], A](upstream: PatchStreamT[M, A])
def flatMap[B](f: A => PatchStreamT[M, B])(using M: Nondeterminism[M]): PatchStreamT[M, B]

Returns a new data-binding sequence by applying a function to all elements of this sequence and using the elements of the resulting collections.

Returns a new data-binding sequence by applying a function to all elements of this sequence and using the elements of the resulting collections.

Whenever upstream or one of the subsequence changes, the result sequence changes accordingly. The time complexity to update the result sequence, when upstream changes, is O(log(n) + c), where n is the size of upstream, and c is number of elements in upstream, mapped to mutable subsequences by f, of which the indices in upstream are changing. For example, if the size of upstream is 10 and 4 elements of them mapped to mutable subsequences, when an element is prepended to upstream, c is 4. However when an element is appended to upstream, c is zero, because no element's index in `upstream is changed.

The time complexity to update the result sequence, when one of the subsequence changes, is O(log(n)), where n is the size of upstream.

Example

Given a source PatchStreamT from an iterable,

import scala.concurrent.Future
import scalaz.std.scalaFuture.given
val bindingSeq = PatchStreamT.fromIterable[Future, String](Seq("foo", "bar"))

when flat-mapping it to more PatchStreamT,

val flatten = bindingSeq.flatMap { s =>
 PatchStreamT.fromIterable(s)
}

then it should returns a StreamT including each intermediate states during flat-mapping

import com.thoughtworks.dsl.keywords.Await
import com.thoughtworks.dsl.macros.Reset.Default.*
`*`[Future] {
 val snapshotLazyList = !Await(flatten.snapshots.toLazyList)
 snapshotLazyList.map(_.toList.mkString) should be(
   LazyList(
     "",
     "foo",
     "foobar",
   )
 )
}
def memoize(using Functor[M]): PatchStreamT[M, A]
def mergeMap[B](mapper: A => CovariantStreamT[M, B])(using M: Nondeterminism[M]): CovariantStreamT[M, B]
def noSkip(using Monad[M]): PatchStreamT[M, A]
def snapshots(using Applicative[M]): CovariantStreamT[M, FingerTree[Int, A]]

Return a CovariantStreamT, whose each element is a scalaz.FingerTree representing the snapshot of the sequence at that time.

Return a CovariantStreamT, whose each element is a scalaz.FingerTree representing the snapshot of the sequence at that time.

Note

The measurement of the scalaz.FingerTree is the size.

Example

Given a PatchStreamT created from an iterable,

import scala.concurrent.Future
import scalaz.std.scalaFuture.given
val bindingSeq = PatchStreamT.fromIterable[Future, String](Seq("foo", "bar", "baz"))

when taking snapshots,

val snapshots = bindingSeq.snapshots

then it should contains an empty value and an initial value

import com.thoughtworks.dsl.keywords.Await
import com.thoughtworks.dsl.macros.Reset.Default.*
`*`[Future] {
 val snapshotLazyList = !Await(snapshots.toLazyList)
 inside(snapshotLazyList) {
   case LazyList(empty, initial) =>
     empty.toList should be(Nil)
     initial.toList should be(List("foo", "bar", "baz"))
 }
}
def zipWithIndex(using Applicative[M]): PatchStreamT[M, (A, CovariantStreamT[M, Int])]