_zip

trait _zip[A]
class java.lang.Object
trait scala.Matchable
class Any
trait _build
object Stream

Def

inline def unzip[B,C](using f: A => (B, C)): (Stream[B], Stream[C])

Unzips stream in two

Unzips stream in two

Unzips a stream of tupled values in two

 val pairs = ('a' <> 'g').stream.zipValue(_.toUpper).pack

 pairs.stream.tp  // Prints Stream((a,A), (b,B), (c,C), (d,D), (e,E), (f,F), (g,G))

 val (left, right) = pairs.stream.unzip

 left.tp   // Prints Stream(a, b, c, d, e, f, g)

 right.tp  // Prints Stream(G, F, E, D, C, B, A)
Source
_zip.scala
inline def zip[B](that: Stream[B]): Stream[(A, B)]

Merge

Merge

Merges two streams in one, creating tuples of corresponding elements

  (1 <> 100).stream.zip('A' <> 'D').tp  // Prints Stream((1,A), (2,B), (3,C), (4,D))

If one of the streams is shorter, the excess elements are lost

Source
_zip.scala
inline def zipAll[B](that: Stream[B], thisDflt: Opt[A], thatDflt: Opt[B]): Stream[(A, B)]

Merge stream

Merge stream

Merges two streams in one, creating tuples of corresponding elements

If one of the streams is shorter, the provided defaults are used. If the default is not available, operation fails

  ('a' <> 'f').stream.zip('A' <> 'H', '?', '?').tp

  // Output
  Stream((a,A), (b,B), (c,C), (d,D), (e,E), (f,F), (?,G), (?,H))
Value Params
that

the stream to merge with this

thatDflt

if that Stream has fewer elements, ''thatDflt'' will be used to fill the voids. Fails if ''thatDflt'' is required, but not available

thisDflt

if this Stream has fewer elements, ''thisDflt'' will be used to fill the voids. Fails if ''thisDflt'' is required, but not available

Source
_zip.scala
inline def zipFoldAs[B](start: B, f: (B, A) => B): Stream[(A, B)]

Merges current folding value

Merges current folding value

(1 <> 7).stream.zipFoldAs(0L)(_ + _).print

// "Running Total" Output
-- --
?  ?
-- --
1  1
2  3
3  6
4  10
5  15
6  21
7  28
Source
_zip.scala
inline def zipIndex: Stream[(Int, A)]

Merge index

Merge index

Creates a new Stream with elements paired with their sequential position, starting at 0

  ('A' <> 'F').stream.zipIndex.tp

  // Output

  Stream((0,A), (1,B), (2,C), (3,D), (4,E), (5,F))

Note: Index is the first element in the resulting tuples

Source
_zip.scala
inline def zipIndex(start: Int): Stream[(Int, A)]

Merge number Creates a new Stream with elements paired with their sequential position Note: Index is the first element in the resulting tuples.

Merge number Creates a new Stream with elements paired with their sequential position Note: Index is the first element in the resulting tuples.

   ('A' <> 'F').stream.zipIndex('A'.toInt) tp  // Prints Stream((65,A), (66,B), (67,C), (68,D), (69,E), (70,F))
Value Params
start

index initial value

Source
_zip.scala
inline def zipKey[B](f: A => B): Stream[(B, A)]

Merge property first

Merge property first

Creates a new Stream with elements paired with their property, defined by given function

The paired value is in the first tuple position

  ('A' <> 'F').stream.zipKey(_.toInt).tp  // Prints Stream((65,A), (66,B), (67,C), (68,D), (69,E), (70,F))
Source
_zip.scala
inline def zipNext: Stream[(A, Opt[A])]

Merge with next

Merge with next

Creates new Stream with elements paired with the optional next element

  (1 <> 5).stream.zipNext.tp  // Prints Stream((1,Opt(2)), (2,Opt(3)), (3,Opt(4)), (4,Opt(5)), (5,Opt(VOID)))
Source
_zip.scala
inline def zipPrior: Stream[(Opt[A], A)]

Merge with prior

Merge with prior

Creates new Stream with elements paired with the optional prior element

  (1 <> 5).stream.zipPrior.tp  // Prints Stream((Opt(VOID),1), (Opt(1),2), (Opt(2),3), (Opt(3),4), (Opt(4),5))
Source
_zip.scala
inline def zipValue[B](f: A => B): Stream[(A, B)]

Merge property

Merge property

Creates a new Stream with elements paired with their property, defined by given function

The paired value is in the second tuple position

  ('A' <> 'F').stream.zipValue(_.toInt).tp  // Prints Stream((A,65), (B,66), (C,67), (D,68), (E,69), (F,70))
Source
_zip.scala