final class InvariantOps[F[_], O] extends AnyVal
- Alphabetic
- By Inheritance
- InvariantOps
- AnyVal
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
def
+(other: String): String
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to any2stringadd[InvariantOps[F, O]] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
++[O2 >: O](s2: ⇒ Stream[F, O2]): Stream[F, O2]
Appends
s2
to the end of this stream. -
def
->[B](y: B): (InvariantOps[F, O], B)
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to ArrowAssoc[InvariantOps[F, O]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
def
>>[O2](s2: ⇒ Stream[F, O2]): Stream[F, O2]
Alias for
flatMap(_ => s2)
. -
def
append[O2 >: O](s2: ⇒ Stream[F, O2]): Stream[F, O2]
Appends
s2
to the end of this stream.Appends
s2
to the end of this stream. Alias fors1 ++ s2
. -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
changes(implicit eq: Eq[O]): Stream[F, O]
Emits only elements that are distinct from their immediate predecessors, using natural equality for comparison.
Emits only elements that are distinct from their immediate predecessors, using natural equality for comparison.
scala> import cats.implicits._ scala> Stream(1,1,2,2,2,3,3).changes.toList res0: List[Int] = List(1, 2, 3)
Example: -
def
concurrently[O2](that: Stream[F, O2])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Runs the supplied stream in the background as elements from this stream are pulled.
Runs the supplied stream in the background as elements from this stream are pulled.
The resulting stream terminates upon termination of this stream. The background stream will be interrupted at that point. Early termination of
that
does not terminate the resulting stream.Any errors that occur in either
this
orthat
stream result in the overall stream terminating with an error.Upon finalization, the resulting stream will interrupt the background stream and wait for it to be finalized.
This method is similar to
this mergeHaltL that.drain
but ensures thethat.drain
stream continues to be evaluated regardless of howthis
is evaluated or how the resulting stream is processed. This method is also similar toStream(this,that).join(2)
but terminatesthat
upon termination ofthis
.scala> import cats.effect.IO, scala.concurrent.ExecutionContext.Implicits.global scala> val data: Stream[IO,Int] = Stream.range(1, 10).covary[IO] scala> Stream.eval(async.signalOf[IO,Int](0)).flatMap(s => Stream(s).concurrently(data.evalMap(s.set))).flatMap(_.discrete).takeWhile(_ < 9, true).runLast.unsafeRunSync res0: Option[Int] = Some(9)
Example: -
def
covary[F2[x] >: F[x]]: Stream[F2, O]
Lifts this stream to the specified effect type.
Lifts this stream to the specified effect type.
scala> import cats.effect.IO scala> Stream(1, 2, 3).covary[IO] res0: Stream[IO,Int] = Stream(..)
Example: -
def
covaryAll[F2[x] >: F[x], O2 >: O]: Stream[F2, O2]
Lifts this stream to the specified effect and output types.
Lifts this stream to the specified effect and output types.
scala> import cats.effect.IO scala> Stream.empty.covaryAll[IO,Int] res0: Stream[IO,Int] = Stream(..)
Example: -
def
diamond[B, C, D](f: Pipe[F, O, B])(qs: F[Queue[F, Option[Segment[O, Unit]]]], g: Pipe[F, O, C])(combine: Pipe2[F, B, C, D])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, D]
Pass elements of
s
through bothf
andg
, then combine the two resulting streams.Pass elements of
s
through bothf
andg
, then combine the two resulting streams. Implemented by enqueueing elements as they are seen byf
onto aQueue
used by theg
branch. USE EXTREME CARE WHEN USING THIS FUNCTION. Deadlocks are possible ifcombine
pulls from theg
branch synchronously before the queue has been populated by thef
branch.The
combine
function receives anF[Int]
effect which evaluates to the current size of theg
-branch's queue.When possible, use one of the safe combinators like
observe
, which are built using this function, in preference to using this function directly. -
def
either[O2](that: Stream[F, O2])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, Either[O, O2]]
Like
merge
, but tags each output with the branch it came from.Like
merge
, but tags each output with the branch it came from.scala> import scala.concurrent.duration._, scala.concurrent.ExecutionContext.Implicits.global, cats.effect.IO scala> val s = Scheduler[IO](1).flatMap { scheduler => | val s1 = scheduler.awakeEvery[IO](1000.millis).scan(0)((acc, i) => acc + 1) | s1.either(scheduler.sleep_[IO](500.millis) ++ s1).take(10) | } scala> s.take(10).runLog.unsafeRunSync res0: Vector[Either[Int,Int]] = Vector(Left(0), Right(0), Left(1), Right(1), Left(2), Right(2), Left(3), Right(3), Left(4), Right(4))
Example: -
def
ensuring(cond: (InvariantOps[F, O]) ⇒ Boolean, msg: ⇒ Any): InvariantOps[F, O]
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to Ensuring[InvariantOps[F, O]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: (InvariantOps[F, O]) ⇒ Boolean): InvariantOps[F, O]
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to Ensuring[InvariantOps[F, O]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): InvariantOps[F, O]
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to Ensuring[InvariantOps[F, O]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): InvariantOps[F, O]
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to Ensuring[InvariantOps[F, O]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
evalMap[O2](f: (O) ⇒ F[O2]): Stream[F, O2]
Alias for
flatMap(o => Stream.eval(f(o)))
.Alias for
flatMap(o => Stream.eval(f(o)))
.scala> import cats.effect.IO scala> Stream(1,2,3,4).evalMap(i => IO(println(i))).run.unsafeRunSync res0: Unit = ()
Example: -
def
evalScan[O2](z: O2)(f: (O2, O) ⇒ F[O2]): Stream[F, O2]
Like
Stream#scan
, but accepts a function returning anF[_]
.Like
Stream#scan
, but accepts a function returning anF[_]
.scala> import cats.effect.IO scala> Stream(1,2,3,4).evalScan(0)((acc,i) => IO(acc + i)).runLog.unsafeRunSync res0: Vector[Int] = Vector(0, 1, 3, 6, 10)
Example: -
def
flatMap[O2](f: (O) ⇒ Stream[F, O2]): Stream[F, O2]
Creates a stream whose elements are generated by applying
f
to each output of the source stream and concatenated all of the results.Creates a stream whose elements are generated by applying
f
to each output of the source stream and concatenated all of the results.scala> Stream(1, 2, 3).flatMap { i => Stream.segment(Segment.seq(List.fill(i)(i))) }.toList res0: List[Int] = List(1, 2, 2, 3, 3, 3)
Example: -
def
foldMonoid(implicit O: Monoid[O]): Stream[F, O]
Folds this stream with the monoid for
O
.Folds this stream with the monoid for
O
.scala> import cats.implicits._ scala> Stream(1, 2, 3, 4, 5).foldMonoid.toList res0: List[Int] = List(15)
Example: -
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to StringFormat[InvariantOps[F, O]] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
def
handleErrorWith[O2 >: O](h: (Throwable) ⇒ Stream[F, O2]): Stream[F, O2]
If
this
terminates withStream.raiseError(e)
, invokeh(e)
.If
this
terminates withStream.raiseError(e)
, invokeh(e)
.scala> Stream(1, 2, 3).append(Stream.raiseError(new RuntimeException)).handleErrorWith(t => Stream(0)).toList res0: List[Int] = List(1, 2, 3, 0)
Example: -
def
interleave(that: Stream[F, O]): Stream[F, O]
Determinsitically interleaves elements, starting on the left, terminating when the end of either branch is reached naturally.
Determinsitically interleaves elements, starting on the left, terminating when the end of either branch is reached naturally.
scala> Stream(1, 2, 3).interleave(Stream(4, 5, 6, 7)).toList res0: List[Int] = List(1, 4, 2, 5, 3, 6)
Example: -
def
interleaveAll(that: Stream[F, O]): Stream[F, O]
Determinsitically interleaves elements, starting on the left, terminating when the ends of both branches are reached naturally.
Determinsitically interleaves elements, starting on the left, terminating when the ends of both branches are reached naturally.
scala> Stream(1, 2, 3).interleaveAll(Stream(4, 5, 6, 7)).toList res0: List[Int] = List(1, 4, 2, 5, 3, 6, 7)
Example: -
def
interruptWhen(haltWhenTrue: Signal[F, Boolean])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Alias for
interruptWhen(haltWhenTrue.discrete)
. -
def
interruptWhen(haltWhenTrue: Stream[F, Boolean])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Let through the
s2
branch as long as thes1
branch isfalse
, listening asynchronously for the left branch to becometrue
.Let through the
s2
branch as long as thes1
branch isfalse
, listening asynchronously for the left branch to becometrue
. This halts as soon as either branch halts.Consider using the overload that takes a
Signal
.Caution: interruption is checked as elements are pulled from the returned stream. As a result, streams which stop pulling from the returned stream end up uninterrubtible. For example,
s.interruptWhen(s2).flatMap(_ => infiniteStream)
will not be interrupted whens2
is true becauses1.interruptWhen(s2)
is never pulled for another element after the first element has been emitted. To fix, considers.flatMap(_ => infiniteStream).interruptWhen(s2)
. -
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
join[O2](maxOpen: Int)(implicit ev: <:<[O, Stream[F, O2]], F: Effect[F], ec: ExecutionContext): Stream[F, O2]
Nondeterministically merges a stream of streams (
outer
) in to a single stream, opening at mostmaxOpen
streams at any point in time.Nondeterministically merges a stream of streams (
outer
) in to a single stream, opening at mostmaxOpen
streams at any point in time.The outer stream is evaluated and each resulting inner stream is run concurrently, up to
maxOpen
stream. Once this limit is reached, evaluation of the outer stream is paused until one or more inner streams finish evaluating.When the outer stream stops gracefully, all inner streams continue to run, resulting in a stream that will stop when all inner streams finish their evaluation.
When the outer stream fails, evaluation of all inner streams is interrupted and the resulting stream will fail with same failure.
When any of the inner streams fail, then the outer stream and all other inner streams are interrupted, resulting in stream that fails with the error of the stream that caused initial failure.
Finalizers on each inner stream are run at the end of the inner stream, concurrently with other stream computations.
Finalizers on the outer stream are run after all inner streams have been pulled from the outer stream but not before all inner streams terminate -- hence finalizers on the outer stream will run AFTER the LAST finalizer on the very last inner stream.
Finalizers on the returned stream are run after the outer stream has finished and all open inner streams have finished.
- maxOpen
Maximum number of open inner streams at any time. Must be > 0.
-
def
joinUnbounded[O2](implicit ev: <:<[O, Stream[F, O2]], F: Effect[F], ec: ExecutionContext): Stream[F, O2]
Like join but races all inner streams simultaneously.
-
def
merge[O2 >: O](that: Stream[F, O2])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O2]
Interleaves the two inputs nondeterministically.
Interleaves the two inputs nondeterministically. The output stream halts after BOTH
s1
ands2
terminate normally, or in the event of an uncaught failure on eithers1
ors2
. Has the property thatmerge(Stream.empty, s) == s
andmerge(raiseError(e), s)
will eventually terminate withraiseError(e)
, possibly after emitting some elements ofs
first.Note:
this
andthat
are each pulled for a segment. Upon receiving a segment, it is emitted downstream. Depending on how that element is processed, the remainder ofthis
andthat
may never be consulted again (e.g.,a.merge(b) >> Stream.constant(0)
). A common case where this can be problematic is draining a stream that publishes to a concurrent data structure and merging it with a consumer from the same data structure. In such cases, useconsumer.concurrently(producer)
instead ofconsumer.mergeHaltR(producer.drain)
to ensure the producer continues to run in parallel with consumer processing.scala> import scala.concurrent.duration._, scala.concurrent.ExecutionContext.Implicits.global, cats.effect.IO scala> val s = Scheduler[IO](1).flatMap { scheduler => | val s1 = scheduler.awakeEvery[IO](500.millis).scan(0)((acc, i) => acc + 1) | s1.merge(scheduler.sleep_[IO](250.millis) ++ s1) | } scala> s.take(6).runLog.unsafeRunSync res0: Vector[Int] = Vector(0, 0, 1, 1, 2, 2)
Example: -
def
mergeHaltBoth[O2 >: O](that: Stream[F, O2])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O2]
Like
merge
, but halts as soon as _either_ branch halts. -
def
mergeHaltL[O2 >: O](that: Stream[F, O2])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O2]
Like
merge
, but halts as soon as thes1
branch halts. -
def
mergeHaltR[O2 >: O](that: Stream[F, O2])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O2]
Like
merge
, but halts as soon as thes2
branch halts. -
def
observe(sink: Sink[F, O])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Synchronously sends values through
sink
.Synchronously sends values through
sink
.scala> import scala.concurrent.ExecutionContext.Implicits.global, cats.effect.IO, cats.implicits._ scala> Stream(1, 2, 3).covary[IO].observe(Sink.showLinesStdOut).map(_ + 1).runLog.unsafeRunSync res0: Vector[Int] = Vector(2, 3, 4)
Example: -
def
observe1(f: (O) ⇒ F[Unit])(implicit F: Functor[F]): Stream[F, O]
Like
observe
but observes with a functionO => F[Unit]
instead of a sink.Like
observe
but observes with a functionO => F[Unit]
instead of a sink. Alias forevalMap(o => f(o).as(o))
. -
def
observeAsync(maxQueued: Int)(sink: Sink[F, O])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Send chunks through
sink
, allowing up tomaxQueued
pending _chunks_ before blockings
. -
def
onComplete[O2 >: O](s2: ⇒ Stream[F, O2]): Stream[F, O2]
Run
s2
afterthis
, regardless of errors duringthis
, then reraise any errors encountered duringthis
.Run
s2
afterthis
, regardless of errors duringthis
, then reraise any errors encountered duringthis
.Note: this should *not* be used for resource cleanup! Use
bracket
oronFinalize
instead.scala> Stream(1, 2, 3).onComplete(Stream(4, 5)).toList res0: List[Int] = List(1, 2, 3, 4, 5)
Example: -
def
onFinalize(f: F[Unit])(implicit F: Applicative[F]): Stream[F, O]
Run the supplied effectful action at the end of this stream, regardless of how the stream terminates.
-
def
pauseWhen(pauseWhenTrue: Signal[F, Boolean])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Alias for
pauseWhen(pauseWhenTrue.discrete)
. -
def
pauseWhen(pauseWhenTrue: Stream[F, Boolean])(implicit F: Effect[F], ec: ExecutionContext): Stream[F, O]
Like
interrupt
but resumes the stream when left branch goes to true. -
def
prefetch(implicit ec: ExecutionContext, F: Effect[F]): Stream[F, O]
Behaves like
identity
, but starts fetching the next segment before emitting the current, enabling processing on either side of theprefetch
to run in parallel. -
def
pull: ToPull[F, O]
Gets a projection of this stream that allows converting it to a
Pull
in a number of ways. -
def
reduceSemigroup(implicit S: Semigroup[O]): Stream[F, O]
Reduces this stream with the Semigroup for
O
.Reduces this stream with the Semigroup for
O
.scala> import cats.implicits._ scala> Stream("The", "quick", "brown", "fox").intersperse(" ").reduceSemigroup.toList res0: List[String] = List(The quick brown fox)
Example: -
def
repartition(f: (O) ⇒ Chunk[O])(implicit S: Semigroup[O]): Stream[F, O]
Repartitions the input with the function
f
.Repartitions the input with the function
f
. On each stepf
is applied to the input and all elements but the last of the resulting sequence are emitted. The last element is then appended to the next input using the SemigroupS
.scala> import cats.implicits._ scala> Stream("Hel", "l", "o Wor", "ld").repartition(s => Chunk.array(s.split(" "))).toList res0: List[String] = List(Hello, World)
Example: -
def
repeatPull[O2](using: (ToPull[F, O]) ⇒ Pull[F, O2, Option[Stream[F, O]]]): Stream[F, O2]
Repeatedly invokes
using
, running the resultantPull
each time, halting when a pull returnsNone
instead ofSome(nextStream)
. -
def
run(implicit F: Sync[F]): F[Unit]
Interprets this stream in to a value of the target effect type
F
and discards any output values of the stream.Interprets this stream in to a value of the target effect type
F
and discards any output values of the stream.To access the output values of the stream, use one of the other methods that start with
run
-- e.g., runFold, runLog, etc.When this method has returned, the stream has not begun execution -- this method simply compiles the stream down to the target effect type.
-
def
runFold[B](init: B)(f: (B, O) ⇒ B)(implicit F: Sync[F]): F[B]
Interprets this stream in to a value of the target effect type
F
by folding the output values together, starting with the providedinit
and combining the current value with each output value.Interprets this stream in to a value of the target effect type
F
by folding the output values together, starting with the providedinit
and combining the current value with each output value.When this method has returned, the stream has not begun execution -- this method simply compiles the stream down to the target effect type.
-
def
runFoldMonoid(implicit F: Sync[F], O: Monoid[O]): F[O]
Like runFold but uses the implicitly available
Monoid[O]
to combine elements.Like runFold but uses the implicitly available
Monoid[O]
to combine elements.scala> import cats.implicits._, cats.effect.IO scala> Stream(1, 2, 3, 4, 5).covary[IO].runFoldMonoid.unsafeRunSync res0: Int = 15
Example: -
def
runFoldSemigroup(implicit F: Sync[F], O: Semigroup[O]): F[Option[O]]
Like runFold but uses the implicitly available
Semigroup[O]
to combine elements.Like runFold but uses the implicitly available
Semigroup[O]
to combine elements. If the stream emits no elements,None
is returned.scala> import cats.implicits._, cats.effect.IO scala> Stream(1, 2, 3, 4, 5).covary[IO].runFoldSemigroup.unsafeRunSync res0: Option[Int] = Some(15) scala> Stream.empty.covaryAll[IO,Int].runFoldSemigroup.unsafeRunSync res1: Option[Int] = None
Example: -
def
runLast(implicit F: Sync[F]): F[Option[O]]
Interprets this stream in to a value of the target effect type
F
, returningNone
if the stream emitted no values and returning the last value emitted wrapped inSome
if values were emitted.Interprets this stream in to a value of the target effect type
F
, returningNone
if the stream emitted no values and returning the last value emitted wrapped inSome
if values were emitted.When this method has returned, the stream has not begun execution -- this method simply compiles the stream down to the target effect type.
To call this method, an
Effect[F]
instance must be implicitly available.scala> import cats.effect.IO scala> Stream.range(0,100).take(5).covary[IO].runLast.unsafeRunSync res0: Option[Int] = Some(4)
Example: -
def
runLog(implicit F: Sync[F]): F[Vector[O]]
Interprets this stream in to a value of the target effect type
F
by logging the output values to aVector
.Interprets this stream in to a value of the target effect type
F
by logging the output values to aVector
.When this method has returned, the stream has not begun execution -- this method simply compiles the stream down to the target effect type.
To call this method, an
Effect[F]
instance must be implicitly available.scala> import cats.effect.IO scala> Stream.range(0,100).take(5).covary[IO].runLog.unsafeRunSync res0: Vector[Int] = Vector(0, 1, 2, 3, 4)
Example: -
def
scanSegments[S, O2](init: S)(f: (S, Segment[O, Unit]) ⇒ Segment[O2, S]): Stream[F, O2]
Like
scan
butf
is applied to each segment of the source stream.Like
scan
butf
is applied to each segment of the source stream. The resulting segment is emitted and the result of the segment is used in the next invocation off
.Many stateful pipes can be implemented efficiently (i.e., supporting fusion) with this method.
-
def
scanSegmentsOpt[S, O2](init: S)(f: (S) ⇒ Option[(Segment[O, Unit]) ⇒ Segment[O2, S]]): Stream[F, O2]
More general version of
scanSegments
where the current state (i.e.,S
) can be inspected to determine if another segment should be pulled or if the stream should terminate.More general version of
scanSegments
where the current state (i.e.,S
) can be inspected to determine if another segment should be pulled or if the stream should terminate. Termination is signaled by returningNone
fromf
. Otherwise, a function which consumes the next segment is returned wrapped inSome
.scala> def take[F[_],O](s: Stream[F,O], n: Long): Stream[F,O] = | s.scanSegmentsOpt(n) { n => if (n <= 0) None else Some(_.take(n).mapResult(_.fold(_._2, _ => 0))) } scala> take(Stream.range(0,100), 5).toList res0: List[Int] = List(0, 1, 2, 3, 4)
Example: -
def
through[O2](f: Pipe[F, O, O2]): Stream[F, O2]
Transforms this stream using the given
Pipe
.Transforms this stream using the given
Pipe
.scala> Stream("Hello", "world").through(text.utf8Encode).toVector.toArray res0: Array[Byte] = Array(72, 101, 108, 108, 111, 119, 111, 114, 108, 100)
Example: -
def
through2[O2, O3](s2: Stream[F, O2])(f: Pipe2[F, O, O2, O3]): Stream[F, O3]
Transforms this stream and
s2
using the givenPipe2
. -
def
through2Pure[O2, O3](s2: Stream[F, O2])(f: Pipe2[Pure, O, O2, O3]): Stream[F, O3]
Transforms this stream and
s2
using the given purePipe2
.Transforms this stream and
s2
using the given purePipe2
.Sometimes this has better type inference than
through2
(e.g., whenF
isNothing
). -
def
throughPure[O2](f: Pipe[Pure, O, O2]): Stream[F, O2]
Transforms this stream using the given pure
Pipe
.Transforms this stream using the given pure
Pipe
.Sometimes this has better type inference than
through
(e.g., whenF
isNothing
). -
def
to(f: Sink[F, O]): Stream[F, Unit]
Applies the given sink to this stream.
Applies the given sink to this stream.
scala> import cats.effect.IO, cats.implicits._ scala> Stream(1,2,3).covary[IO].to(Sink.showLinesStdOut).run.unsafeRunSync res0: Unit = ()
Example: -
def
toString(): String
- Definition Classes
- Any
-
def
translate[G[_]](u: ~>[F, G]): Stream[G, O]
Translates effect type from
F
toG
using the suppliedFunctionK
. -
def
zip[O2](that: Stream[F, O2]): Stream[F, (O, O2)]
Determinsitically zips elements, terminating when the end of either branch is reached naturally.
Determinsitically zips elements, terminating when the end of either branch is reached naturally.
scala> Stream(1, 2, 3).zip(Stream(4, 5, 6, 7)).toList res0: List[(Int,Int)] = List((1,4), (2,5), (3,6))
Example: -
def
zipAll[O2](that: Stream[F, O2])(pad1: O, pad2: O2): Stream[F, (O, O2)]
Determinsitically zips elements, terminating when the ends of both branches are reached naturally, padding the left branch with
pad1
and padding the right branch withpad2
as necessary.Determinsitically zips elements, terminating when the ends of both branches are reached naturally, padding the left branch with
pad1
and padding the right branch withpad2
as necessary.scala> Stream(1,2,3).zipAll(Stream(4,5,6,7))(0,0).toList res0: List[(Int,Int)] = List((1,4), (2,5), (3,6), (0,7))
Example: -
def
zipAllWith[O2, O3](that: Stream[F, O2])(pad1: O, pad2: O2)(f: (O, O2) ⇒ O3): Stream[F, O3]
Determinsitically zips elements with the specified function, terminating when the ends of both branches are reached naturally, padding the left branch with
pad1
and padding the right branch withpad2
as necessary.Determinsitically zips elements with the specified function, terminating when the ends of both branches are reached naturally, padding the left branch with
pad1
and padding the right branch withpad2
as necessary.scala> Stream(1,2,3).zipAllWith(Stream(4,5,6,7))(0, 0)(_ + _).toList res0: List[Int] = List(5, 7, 9, 7)
Example: -
def
zipWith[O2, O3](that: Stream[F, O2])(f: (O, O2) ⇒ O3): Stream[F, O3]
Determinsitically zips elements using the specified function, terminating when the end of either branch is reached naturally.
Determinsitically zips elements using the specified function, terminating when the end of either branch is reached naturally.
scala> Stream(1, 2, 3).zipWith(Stream(4, 5, 6, 7))(_ + _).toList res0: List[Int] = List(5, 7, 9)
Example: -
def
→[B](y: B): (InvariantOps[F, O], B)
- Implicit
- This member is added by an implicit conversion from InvariantOps[F, O] to ArrowAssoc[InvariantOps[F, O]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc