_zip

trait _zip
class java.lang.Object
trait scala.Matchable
class Any
trait _build
object ~

Def

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

Unzips stream in two

Unzips stream in two

Unzips a stream of tupled values in two

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

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

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

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

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

Merge

Merge

Merges two streams in one, creating tuples of corresponding elements

  (1 <> 100).~.zip('A' <> 'D').tp  // Prints ~((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[A](inline that: ~[B], thisDflt: Opt[A], thatDflt: Opt[B]): ~[(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').~.zip('A' <> 'H', '?', '?').tp

  // Output
  ~((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 ~ has fewer elements, ''thatDflt'' will be used to fill the voids. Fails if ''thatDflt'' is required, but not available

thisDflt

if this ~ 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[A](inline start: B, inline f: (B, A) => B): ~[(A, B)]

Merges current folding value

Merges current folding value

(1 <> 7).~.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[A]: ~[(Int, A)]

Merge index

Merge index

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

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

  // Output

  ~((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[A](inline start: Int): ~[(Int, A)]

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

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

   ('A' <> 'F').~.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[A](inline f: A => B): ~[(B, A)]

Merge property first

Merge property first

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

The paired value is in the first tuple position

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

Merge with next

Merge with next

Creates new ~ with elements paired with the optional next element

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

Merge with prior

Merge with prior

Creates new ~ with elements paired with the optional prior element

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

Merge property

Merge property

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

The paired value is in the second tuple position

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