_build

trait _build extends _extend with _filter with _group with _map with _mutate with _order with _parallel with _peek with _zip

Build Stream Interface

Build methods extend stream pipeline creating functionality which will add, remove or modify stream elements, when they finally start moving throught the pipeline.

Once a single stream build method is invoked, the original stream object must not be used, all further processing must be done with the newly created stream.

Source
__.scala
trait _zip
trait _peek
trait _parallel
trait _order
trait _mutate
trait _map
trait _group
trait _filter
trait _drop
trait _take
trait _extend
class java.lang.Object
trait scala.Matchable
class Any
object ~

Def

@scala.annotation.targetName("join")
inline def +[A](inline v: A): ~[A]

Alias for join

Alias for join

Creates a new ~ with given element appended to current ~

  ((1 <> 5).~ + 99 + 100).tp

  // Output
  ~(1, 2, 3, 4, 5, 99, 100)
Inherited from
_extend
Source
_extend.scala
@scala.annotation.targetName("joinAll")
inline def ++[A](inline v: ~[A]): ~[A]

Alias for joinAll

Alias for joinAll

Creates a new ~ with given elements appended to current ~

  (('1' <> '9').~ ++ ('a' <> 'd') ++ ('A' <> 'D')).tp

  // Output
  ~(1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, A, B, C, D)
Inherited from
_extend
Source
_extend.scala
@scala.annotation.targetName("joinAllAt")
inline def ++@[A](inline index: Int, inline v: ~[A]): ~[A]

Alias for joinAllAt

Alias for joinAllAt

Creates a new ~ with given elements inserted into current Stream at given index

If index is out of range, the elements are prepended or appended

   (('a' <> 'f').~ ++@ (3, 'X' <> 'Z')).tp

   // Output
   ~(a, b, c, X, Y, Z, d, e, f)
Inherited from
_extend
Source
_extend.scala
@scala.annotation.targetName("joinAt")
inline def +@[A](inline index: Int, inline v: A): ~[A]

Alias for joinAt

Alias for joinAt

Creates a new ~ with given element inserted into current ~ at given index

If index is out of range, the element is prepended or appended

 (('a' <> 'd').~ +@ (2, 'X')).tp

  // Output
  ~(a, b, X, c, d)
Inherited from
_extend
Source
_extend.scala
inline def collect[A](inline f: scala.PartialFunction[A, B]): ~[B]

Partial map

Partial map

Creates a new ~ by applying a partial function to all elements of current ~ on which the function is defined.

(0 <>> 26).~.collect{
 case i if(i%2==0) => ('a' + i).Char
}.tp

// Output
~(a, c, e, g, i, k, m, o, q, s, u, w, y)

Note:

  • collect is functionally similar to map_?, which is prefferable in most cases.
  • 'partialMap' would be a better name for this operation, but 'collect' is an established Scala convention.
Inherited from
_map
Source
_map.scala
inline def default[A](inline v: => A): ~[A]

Default element

Default element

If current ~ is empty, the given element will be appended

Otherwise current ~ will not change

 (1 <>> 1).~.default(99).tp // Prints ~(99)

 (1 <>> 5).~.default(99).tp // Prints ~(1, 2, 3, 4)
Inherited from
_extend
Source
_extend.scala
inline def drop[A](inline f: A => Boolean): ~[A]

Reverse filter

Reverse filter

Disallows ~ elements satisfying the given function

  (0 <>> 10).~.drop(_ > 5).tp

  // Output
  ~(0, 1, 2, 3, 4, 5)

Note: Scala equivalent is called "filterNot"

Inherited from
_drop
Source
_drop.scala
inline def DROP[A](inline f: A => Boolean): ~[A]

Heavy reversed filter

Heavy reversed filter

Disallows ~ elements satisfying the given function

DROP is functionally equivalent to drop, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.

Inherited from
_drop
Source
_drop.scala
@scala.annotation.targetName("drop_Range")
inline def drop_<>[A](inline i: Int.<>): ~[A]

Range reversed filter

Range reversed filter

Only allows elements outside specified sequencial range

  ('a' <> 'f').~.drop_<>(2 <> 3).tp

  // Output
  ~(a, b, e, f)

Note: Sequence indexing starts from 0

Inherited from
_drop
Source
_drop.scala
def dropAll[A](v: ~[A]): ~[A]

Multi element reversed filter

Multi element reversed filter

Only lets elements not found in given stream

  ('a' <> 'z').~.dropAll('c' <> 'x') .tp       // Prints ~(a, b, y, z)
Inherited from
_drop
Source
_drop.scala
def dropAllBy[A](f: A => B, v: ~[B]): ~[A]

Multi element mapped reversed filter

Multi element mapped reversed filter

Only lets elements, which mapped value is not found in given stream

  ('a' <> 'z').~.dropAllBy(_.Int % 10, ~~(1,3,7,4,6)).tp

  // Output
  ~(b, c, d, f, i, l, m, n, p, s, v, w, x, z)
Inherited from
_drop
Source
_drop.scala
inline def dropEvery[A](nTh: Int): ~[A]

Every Nth element reversed filter

Every Nth element reversed filter

Drops every nTh element

  (1 <> 10).~.dropEvery(3).tp   // Prints: ~(1, 2, 4, 5, 7, 8, 10)
Inherited from
_drop
Source
_drop.scala
inline def dropFirst[A](inline n: Int): ~[A]

Head reversed filter

Head reversed filter

Drops given number of first elements

  (1 <> 10).~.dropFirst(3).tp  // Prints  ~(4, 5, 6, 7, 8, 9, 10)
Inherited from
_drop
Source
_drop.scala
inline def dropLast[A](n: Int): ~[A]

Tail reversed filter

Tail reversed filter

Drops given number of elements coming last

  (1 <> 10).~.dropLast(3).tp  // Prints  ~(1, 2, 3, 4, 5, 6, 7)

Note: This method will block on unlimited streams

Inherited from
_drop
Source
_drop.scala
def dropOnly[A](v: A, vs: A*): ~[A]

Single value reversed filter

Single value reversed filter

Drops only specified value.

  (1 <> 4).~.dropOnly(3).tp

  // Output
  ~(1, 2, 4)

Note: dropOnly is more efficient than general filter, because there is no function involved.

Inherited from
_drop
Source
_drop.scala
def dropOnlyBy[A](f: A => B, vs: B*): ~[A]
Inherited from
_drop
Source
_drop.scala
inline def dropSame[A]: ~[A]

Duplicates reversed filter

Duplicates reversed filter

Drops elements equal to the passed in prior position

Note: To generally get rid of all duplicates, the stream must be sorted to arrange duplicates in sequence

Inherited from
_drop
Source
_drop.scala
inline def dropSameBy[A](inline f: A => B): ~[A]

Mapped duplicates reversed filter

Mapped duplicates reversed filter

Drops elements, which evaluate to the same value as elements passed in prior position

Note: To generally get rid of all duplicates, the stream must be sorted by the mapping function

  (1 <> 100).~.dropSameBy(_.toString.length).tp

  // Output
  ~(1, 10, 100)
Inherited from
_drop
Source
_drop.scala
def dropVoid[A](using Given.VoidTag[A]): ~[A]

Void value reversed filter

Void value reversed filter

Drops elements which test to be void

Inherited from
_drop
Source
_drop.scala
inline def dropWhile[A](inline f: A => Boolean): ~[A]

Coditional reversed head filter

Coditional reversed head filter

Discards first consecutive elements satisfying the condition

  def stream = (1 <> 5).~ ++ (1 <> 5)

  stream.tp                     // Prints ~(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)

  stream.dropWhile(_ <= 3).tp   // Prints ~(4, 5, 1, 2, 3, 4, 5)

Note: Everything starting from the first non compliant element will be allowed (including later compliant elements)

Inherited from
_drop
Source
_drop.scala
def enablePreview[A]: ~[A] & ~~.Preview[A]

Enables preview capabilities

Enables preview capabilities

Returns ~~.Preview, which allows to pre-load and inspect elements, even before they are read

  def strm : ~[String] = ???

  if(strm.enablePreview.previewSize > 1000) "Stream is over 1K".TP
Inherited from
_mutate
Source
_mutate.scala
def enableSize[A]: ~[A] & Able.Size

Adds sizing information

Adds sizing information

If Stream already has sizing, this method is a simple cast, otherwise, the elements might be buffered and counted.

Inherited from
_mutate
Source
_mutate.scala
inline def filter[A](inline f: A => Boolean): ~[A]

Legacy filter

Legacy filter

Filters ~ elements according to given function

  (0 <>> 10).~.filter(_ > 5).tp

  // Output
  ~(6, 7, 8, 9)

Note: take is usually used instead.

Inherited from
_filter
Source
__.scala
inline def FILTER[A](inline f: A => Boolean): ~[A]
Inherited from
_filter
Source
__.scala
inline def FLAT_MAP[A, T, STM <: ~~.AnyType[T]](inline f: A => ~[B])(using inline s: Given.StreamTag[B, STM]): STM

Heavy flat map

Heavy flat map

FLAT_MAP is functionally equivalent to flatMap, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.

Inherited from
_map
Source
_map.scala
inline def flatMap[A, T, STM <: ~~.AnyType[T]](inline f: A => ~[B])(using inline s: Given.StreamTag[B, STM]): STM

Flat map

Flat map

Creates a new ~ by applying given function to all elements of current ~ and concatenating the results

(1 <> 3).~.flatMap(i => ~~(i, i*10, i*100)).tp

// Output
~(1, 10, 100, 2, 20, 200, 3, 30, 300)
Inherited from
_map
Source
_map.scala
inline def flatten[A, T, STM <: ~~.AnyType[T]](using inline f: A => Able.~[T], inline s: Given.StreamTag[T, ~~._build._map.STM]): STM

Converts a stream of streams into a flat stream

Converts a stream of streams into a flat stream

val vs: ~[~[Char]] = ~~(
  'a' <> 'd',
  ><('x', 'y', 'z'),
  Vector('v', 'e', 'c', 't', 'o', 'r'))

vs.flatten.tp // Prints ~(a, b, c, d, x, y, z, v, e, c, t, o, r)
Inherited from
_map
Source
_map.scala
inline def group[A](inline f: (A, A) => Boolean, inline peek: (A, Boolean) => U): ~[~[A]]

Group by test

Group by test

Puts elements in the same group based on a function test for every two consecutive elements

   // Putting Ints into groups of 3

   (0 <> 20).~.group(_ / 3 == _ / 3).print

   // Output
   ---------------
   ?
   ---------------
   ~(0, 1, 2)
   ~(3, 4, 5)
   ~(6, 7, 8)
   ~(9, 10, 11)
   ~(12, 13, 14)
   ~(15, 16, 17)
   ~(18, 19, 20)
   ---------------
Value Params
f

function for two consecutive elements. if 'false' is returned, the second tested element will start a new group

peek

side-effect convenience function will run for each element. Boolean parameter indicates if the element starts a new group

Inherited from
_group
Source
_group.scala
inline def group[A]: ~[~[A]]

Simple grouping

Simple grouping

Puts consecutive elements in the same group if they are equal

   def stream =  ~~(1, 2, 3).repeat(3)

   stream.tp           // Prints ~(1, 1, 1, 2, 2, 2, 3, 3, 3)

   stream.group.print  // Prints  ------------
                                ?
                                ------------
                                ~(1, 1, 1)
                                ~(2, 2, 2)
                                ~(3, 3, 3)
                                ------------

Note: Non consecutive equal elements will end up in different groups. Prior ordering might be needed

Inherited from
_group
Source
_group.scala
inline def groupBy[A](inline f: A => Any, inline more: A => Any*): ~[~[A]]

Grouping on properties

Grouping on properties

Puts consecutive elements in the same group if all the specified properties are equal

When properties change, a new group is started

    ('#' <> '|').~.groupBy(_.isLetter, _.isDigit).print

   // Output
   ---------------------------------------------------------------------------------
   ?
   ---------------------------------------------------------------------------------
   ~(#, $, %, &, ', (, ), *, +, ,, -, ., /)
   ~(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
   ~(:, ;, <, =, >, ?, @)
   ~(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)
   ~([, \, ], /\, _, `)
   ~(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, p, t, u, v, w, x, y, z)
   ~({, ~)
   ---------------------------------------------------------------------------------
Value Params
properties

a set of functions, each indicating element property

Inherited from
_group
Source
_group.scala
inline def groupEvery[A](inline cnt: Int): ~[~[A]]

Fixed size groups

Fixed size groups

Puts consecutive elements into fixed size groups

('a' <> 'z').~.groupEvery(8).print

// Output
-------------------------
?
-------------------------
~(a, b, c, d, e, f, g, h)
~(i, j, k, l, m, n, o, p)
~(q, r, p, t, u, v, w, x)
~(y, z)
-------------------------
Inherited from
_group
Source
_group.scala
inline def groupWith[A](f: A => B): ~[(B, ~[A])]

Grouping on a property

Grouping on a property

Puts consecutive elements in the same group if their properties are equal

  (0 <> 20).~.groupWith(_ / 3).print

  // Output
  -- -------------
  _1 _2
  -- -------------
  0  ~(0, 1, 2)
  1  ~(3, 4, 5)
  2  ~(6, 7, 8)
  3  ~(9, 10, 11)
  4  ~(12, 13, 14)
  5  ~(15, 16, 17)
  6  ~(18, 19, 20)
  -- -------------

Note: groupWith also returns the groupped property value (unlike groupBy)

Value Params
properties

a set of functions, each indicating an element property

Inherited from
_group
Source
_group.scala
def hideSizeData[A]: ~[A]

Loose size information

Loose size information

Many streams return ''sizeLong_?'', knowing their current size

hideSizeData drops sizing information, so some optimizations will not be available

This is primarily for testing and debugging

Inherited from
_mutate
Source
_mutate.scala
inline def join[A](inline v: A): ~[A]

Join element

Join element

Creates a new ~ with given element appended to current ~

  (1 <> 5).~.join(99).join(100).tp

  // Output
  ~(1, 2, 3, 4, 5, 99, 100)
Inherited from
_extend
Source
_extend.scala
inline def joinAll[A](inline v: ~[A]): ~[A]

Join all

Join all

Creates a new ~ with given elements appended to current ~

  ('1' <> '9').~.joinAll('a' <> 'd').joinAll('A' <> 'D').tp

  // Output
  ~(1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, A, B, C, D)
Inherited from
_extend
Source
_extend.scala
inline def joinAllAt[A](inline index: Int, inline v: ~[A]): ~[A]

Join all at position

Join all at position

Creates a new ~ with given elements inserted into current Stream at given index

If index is out of range, the elements are prepended or appended

   ('a' <> 'f').~.joinAllAt(3, 'X' <> 'Z').tp

   // Output
   ~(a, b, c, X, Y, Z, d, e, f)
Inherited from
_extend
Source
_extend.scala
inline def joinAt[A](inline index: Int, inline v: A): ~[A]

Join element at position

Join element at position

Creates a new ~ with given element inserted into current ~ at given index

If index is out of range, the element is prepended or appended

 ('a' <> 'd').~.joinAt(2, 'X').tp

  // Output
  ~(a, b, X, c, d)
Inherited from
_extend
Source
_extend.scala
def load[A]: ~[A] & Able.Size

Preload all

Preload all

Immediately loads all stream elements into memory, so they are no longer dependent on underlying sources.

  def strm : ~[String] = ???

  strm.load

  // is functionally same as

  strm.toBuffer.~
Inherited from
_mutate
Source
_mutate.scala
inline def map[A, T, STM <: ~~.AnyType[T]](inline f: A => B)(using inline s: Given.StreamTag[B, STM]): STM

Simple map

Simple map

Creates a new ~ where each element is a result of applying given function to current ~ elements

(0 <>> 26).~.map(i => ('a' + i).Char).tp

// Output
~(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
Inherited from
_map
Source
_map.scala
inline def MAP[A, T, STM <: ~~.AnyType[T]](inline f: A => B)(using inline s: Given.StreamTag[B, STM]): STM

Heavy map

Heavy map

MAP is functionally equivalent to map, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.

Inherited from
_map
Source
_map.scala
@scala.annotation.targetName("MAP_Opt")
inline def MAP_?[A, T, STM <: ~~.AnyType[T]](inline f: A => OPT)(using inline s: Given.StreamTag.Opt[T, OPT, STM]): STM

Heavy optional map

Heavy optional map

MAP_? is functionally equivalent to map_?, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.

Inherited from
_map
Source
_map.scala
@scala.annotation.targetName("map_Opt")
inline def map_?[A, T, STM <: ~~.AnyType[T]](inline f: A => OPT)(using inline s: Given.StreamTag.Opt[T, OPT, STM]): STM

Optional map

Optional map

Creates a new ~ where each element is a result of applying given function to ~ elements. If the function returns void option, the element is dropped.

(1 <> 10).~.map_?[Opt[String]](i => if(i>5) "Str_"+i else \/).tp

// Output
~(Str_6, Str_7, Str_8, Str_9, Str_10)

Pattern matching can be used, but the last void case must always be present:

(0 <>> 26).~.map_?[Char.Opt]{
 case i if(i%2==0) => ('a' + i).Char
 case _            => \/
}.tp

// Output
~(a, c, e, g, i, k, m, o, q, s, u, w, y)

Note:

  • map_? is functionally similar to collect, but is faster (PartialFunction has to be evaluated twice)
  • map_? can return specialized stream result, but boxing might happen during mapping
Inherited from
_map
Source
_map.scala
@scala.annotation.targetName("nonEmpty_Opt")
def nonEmpty_?[A]: Opt[~[A]]

Non empty option Optionally returns stream, if it is not empty.

Non empty option Optionally returns stream, if it is not empty.

Note: If stream does not have sizing information, this method will immediately preload at lease the first element.

Inherited from
_mutate
Source
_mutate.scala
def parallel[A]: ~~.Flow[A]

Parallel

Parallel

Returns ~~.Flow with parallel execution

Each consecutive element will be sent to a new thread for processing

  (1 <> 5).~
     .parallel
     .map("Value: " + _ + "\t" + Thread.currentThread.getName)
     .foreach(println)

  // Possible Output
  Value: 1    ForkJoinPool.commonPool-worker-9
  Value: 3    ForkJoinPool.commonPool-worker-11
  Value: 2    main
  Value: 4    ForkJoinPool.commonPool-worker-2
  Value: 5    ForkJoinPool.commonPool-worker-4
Inherited from
_parallel
Source
_parallel.scala
def parallelIf[A](v: Boolean): ~~.Flow[A]

Conditionally parallel

Conditionally parallel

Returns ~~.Flow with parallel or sequential implementation, depending on given parameter

   (1 <> 50).~.parallelIf(true).isParallel   // Returns true

   (1 <> 50).~.parallelIf(false).isParallel  // Returns false
Inherited from
_parallel
Source
_parallel.scala
def parallelIfOver[A](threshold: Int): ~~.Flow[A]

Conditionally parallel

Conditionally parallel

Returns ~~.Flow with parallel or sequential implementation, depending on stream having element count equal or greater than given ''threshold''

  (1 <> 50).~.parallelIfOver(100).isParallel   // Returns false

  (1 <> 200).~.parallelIfOver(100).isParallel  // Returns true
Inherited from
_parallel
Source
_parallel.scala
def parallelWithPriority[A](p: J.Priority, parallelism: Int): ~~.Flow[A]

Parallel with Priority

Parallel with Priority

This is very expensive operation, because it creates a custom thread pool. It only sutable for long running streams

   (1 <> 100).~.parallelWithPriority(MIN, 4).foreach(v => ())

   (1 <> 100).~.parallelWithPriority(MAX).foreach(v => ())

   (1 <> 100).~.parallelWithPriority(J.Priority(5), 4).foreach(v => ())

Note: parallelism determines how many parallel threads are allowed. Default value is CPU core count minus 1

Inherited from
_parallel
Source
_parallel.scala
inline def partition[A](inline p: A => Boolean, inline more: A => Boolean*): ~[~[A]]

Predicate grouping

Predicate grouping

All stream elements are grouped by given predicates, which are applied in sequence. Thus if an element is accepted into a group, it will not be evaluated by the rest of the filters.

The resulting stream size will be equal to the number of predicates plus one. The last group will hold spill over elements, not accepted by any predicate. Groups can be empty.

val ~~(odd,even) = (1 <> 10).~.partition(_ % 2 == 1)

odd.tp
even.tp

// Age groups
(1 <> 80).~.partition(_ <= 12, _ in 13 <> 19, _ < 30, _ in 30 <> 40, _ < 50, _ < 65).print
// Output
~(1, 3, 5, 7, 9)
~(2, 4, 6, 8, 10)

-------------------------------------------------------------------
?
-------------------------------------------------------------------
~(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
~(13, 14, 15, 16, 17, 18, 19)
~(20, 21, 22, 23, 24, 25, 26, 27, 28, 29)
~(30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40)
~(41, 42, 43, 44, 45, 46, 47, 48, 49)
~(50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64)
~(65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80)
-------------------------------------------------------------------
Inherited from
_group
Source
_group.scala
inline def peek[A](inline f: A => U): ~[A]

Inspect

Inspect

The given function will be run with every passing stream element.

  (1 <> 5).~.peek(_.tp).drain

  // Output
  1
  2
  3
  4
  5
Inherited from
_peek
Source
_peek.scala
def peekEmpty[A](f: => U): ~[A]

Peek empty

Peek empty

The given function is executed once, only if stream is empty

  (1 <> 10).~.drop(_ > 0).peekEmpty("Stream is empty".tp).drain

  // Output
  Stream is empty
Inherited from
_peek
Source
_peek.scala
def peekEnd[A](f: (Int, Time.Length) => U): ~[A]

Peek end

Peek end

The given function is executed once, when stream is exhausted

The function receives total element count and Time.Length, it took for all elements to pass

  (1 <> 10).~
    .peek(_ => J.sleep(100.Millis))
    .peekEnd((cnt,time) => "Elements: "+cnt+"  total time: "+time.tag tp())
    .drain

  // Output
  Elements: 10  total time: 0.904106700 sec

Note: This will not run for empty streams

Inherited from
_peek
Source
_peek.scala
def peekEvents[A](f: ~~.Custom.Event => U): ~[A]

Custom events

Custom events

Allows to setup ~~.Custom.Events multiple monitoring events

 (1 <> 1000).~
   .peek(_ => J.sleep(5.Millis))
   .peekEvents(e => {
     e.onBeforeFirst(t   => "Started at: "+ t.dayTime.tag tp())
     e.onEvery(1.Second, (c,t) => "  Processed "+c+" in "+t.tag tp())
     e.onAfterLast((c,t) => "Finished in: "+ t.tag + ",  Element count: " + c tp())
   })
   .drain

 // Output

 Started at: 14:05:39.333
   Processed 187 in 1.018583400 sec
   Processed 371 in 2.020508100 secs
   Processed 557 in 3.021843300 secs
   Processed 743 in 4.023837400 secs
   Processed 928 in 5.026982 secs
 Finished in: 5.411673300 secs, Element count: 1000
Inherited from
_peek
Source
_peek.scala
inline def peekIndexed[A](inline f: (Int, A) => U, inline start: Int): ~[A]

Indexed peek

Indexed peek

The given function will be executed with every passing element and its index.

  ('a' <> 'f').~.peekIndexed((i,c) => (""+i+" : "+c).tp, 1).drain

  // Output
  1 : a
  2 : b
  3 : c
  4 : d
  5 : e
  6 : f

Note. By default indexing starts with 0, but it can be specified

Inherited from
_peek
Source
_peek.scala

Custom monitor

Custom monitor

Adds pre-build ~~.Custom.Event.Monitor

If passed monitor tests to be void (.isEmpty), the operation is ignored

Inherited from
_peek
Source
_peek.scala
def peekStart[A](f: Time => U): ~[A]

Peek start

Peek start

The given function is executed once, just before the first elements is about to pass.

  ('a' <> 'f').~.peekStart(time => "Started at: "+time).drain

Note: This will not run for empty streams

Inherited from
_peek
Source
_peek.scala
inline def raw[A, STM <: ~~.RawType[A]](using inline s: Given.StreamTag.Raw[A, ~~._build._mutate.STM]): STM

Specialized stream

Specialized stream

Converts current stream into specialized on underlying primitive data. If stream is already specialized, the conversion is a simple cas t.

   val s  : ~[Int] = 1 <> 10

   val ss : Int.~  = s.raw

Note: If underlying type is not primitive, the method will not compile

Inherited from
_mutate
Source
_mutate.scala
inline def ref[A]: ~[A]

Generalize

Generalize

If stream is specialized it will be up-cast to general Val.Stream type, and further operations will be general (unless they are specialized, like map)

  val special : Int.><  = (1 <> 10).~.><

  val general : ><[Int] = (1 <> 10).~.ref.><

  special.getClass.tp // Prints class scalqa.lang.int.g.Pack

  general.getClass.tp // Prints class scalqa.val.pack.z.ArrayPack

Note: This is a true zero cost operation. It does not change byte code (only compiler context)

Inherited from
_mutate
Source
_mutate.scala
inline def repeat[A](inline times: Int): ~[A]

Repeat elements

Repeat elements

Creates a new ~ where each elements from current ~ is repeated given number of times

 (0 <> 2).~.repeat(3).tp

 // Output
 ~(0, 0, 0, 1, 1, 1, 2, 2, 2)
Inherited from
_extend
Source
_extend.scala
inline def reverse[A]: ~[A]

Reverse order

Reverse order

Re-arranges all elements is reverse order

('A' <> 'F').~.reverse.tp  // Prints ~(F, E, D, C, B, A)
Inherited from
_mutate
Source
_mutate.scala
inline def reverseEvery[A](inline size: Int): ~[A]

Reverse order in segments

Reverse order in segments

Reverses order of elements within segments of fixed size

(1 <> 15).~.reverseEvery(5).tp

(1 <> 15).~.reverseEvery(5).reverseEvery(3).reverseEvery(7).tp

// Output
~(5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11)

~(7, 2, 1, 10, 5, 4, 3, 12, 11, 6, 15, 14, 9, 8, 13)

Use Case: Predefined Shuffle

For testing purposes it is often required to get elements in random order. However the order cannot be completely random, if we want to replicate bugs

reverseEvery can shuffle elements in a predefined order which looks random

Inherited from
_mutate
Source
_mutate.scala
inline def shuffle[A]: ~[A]

Randomize order

Randomize order

Re-arranges elements is random order

Inherited from
_mutate
Source
_mutate.scala
inline def sliding[A](inline size: Int, inline step: Int): ~[~[A]]

Sliding group view

Sliding group view

Example: group size 3 with step 1

 ('a' <> 'g').~.sliding(3).print

 // Output
 ----------
 ?
 ----------
 ~(a, b, c)
 ~(b, c, d)
 ~(c, d, e)
 ~(d, e, f)
 ~(e, f, g)
 ----------

Example: group size 4 with step 2

 ('a' <> 'g').~.sliding(4,2).print

 // Output
 -------------
 ?
 -------------
 ~(a, b, c, d)
 ~(c, d, e, f)
 ~(e, f, g)
 -------------
Inherited from
_group
Source
_group.scala
inline def sort[A](using inline o: scala.Ordering[A]): ~[A]

Sort

Sort

Sorts stream elements with given Ordering

  ~~(5, 1, 4, 2, 3).sort.tp  // Prints ~(1, 2, 3, 4, 5)
Inherited from
_order
Source
_order.scala
inline def sortBy[A](f1: A => B, f2: A => C, f3: A => D)(using scala.Ordering[B], scala.Ordering[C], scala.Ordering[D]): ~[A]

Sort by three properties

Sort by three properties

Sorts stream on first property, then if indeterminate on second, etc...

Inherited from
_order
Source
_order.scala
inline def sortBy[A](f1: A => B, f2: A => C)(using scala.Ordering[B], scala.Ordering[C]): ~[A]

Sort by two properties

Sort by two properties

Sorts stream on first property, and then, if indeterminate on second

Inherited from
_order
Source
_order.scala
inline def sortBy[A](inline f: A => B)(using inline o: scala.Ordering[B]): ~[A]

Sort by property

Sort by property

Sorts stream of elements based on a single property

  ~~("aaaa", "bb", "ccc", "d").sortBy(_.length).tp

  // Output
  ~(d, bb, ccc, aaaa)
Inherited from
_order
Source
_order.scala
inline def sortReversed[A](using inline o: scala.Ordering[A]): ~[A]

Sort reversed

Sort reversed

Reverse sorts stream elements with given Ordering

  ~~(5, 1, 4, 2, 3).sortReversed.tp  // Prints ~(5, 4, 3, 2, 1)
Inherited from
_order
Source
_order.scala
inline def splitAt[A](inline positions: Int*): ~[~[A]]

Positional split

Positional split

Splits ~ at specified positions

val ~~(s1, s2, s3) = (0 <> 20).~.splitAt(5, 15)

s1.tp   // Prints ~(0, 1, 2, 3, 4)
s2.tp   // Prints ~(5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
s3.tp   // Prints ~(15, 16, 17, 18, 19, 20)

Note. The same could be accomplished with read_~

```

val s3 = (0 <> 20).~ val s1 = s3.read_~(5) val s2 = s3.read_~(10) ```

Inherited from
_group
Source
_group.scala
inline def take[A](inline f: A => Boolean): ~[A]

Main filter

Main filter

Only takes ~ elements satisfying the given function

  (0 <>> 10).~.take(_ > 5).tp

  // Output
  ~(6, 7, 8, 9)

Note: Traditional method filter is also available and can be used, but take is prefferable in most cases.

Inherited from
_take
Source
_take.scala
inline def TAKE[A](inline f: A => Boolean): ~[A]

Heavy filter

Heavy filter

Filters ~ elements according to given function

TAKE is functionally equivalent to take, but is fully inlined. It makes compiled code larger, but guarantees the best possible performance on large streams.

Inherited from
_take
Source
_take.scala
@scala.annotation.targetName("take_Range")
inline def take_<>[A](inline i: Int.<>): ~[A]

Range filter

Range filter

Only allows elements withing specified sequencial range

  ('a' <> 'z').~.take_<>(1 <> 7).tp

  // Output
  ~(b, c, d, e, f, g, h)

Note: Sequence indexing starts from 0

Inherited from
_take
Source
_take.scala
def takeAll[A](v: ~[A]): ~[A]

Multi element filter

Multi element filter

Only lets elements equal to the found in given stream

  ('a' <> 'z').~.takeAll(~~('z','x','b')).tp   // Prints ~('b','x','y')

  ('a' <> 'z').~.takeAll('b' <> 'f') .tp       // Prints ~('b','c','d','e','f')
Inherited from
_take
Source
_take.scala
def takeAllBy[A](f: A => B, v: ~[B]): ~[A]

Multi element mapped filter

Multi element mapped filter

Only lets elements, which mapped value is found in given stream

  ('a' <> 'z').~.takeAllBy(_.Int % 10, ~~(1,3,7)).tp

  // Output
  ~(a, e, g, k, o, q, u, y)
Inherited from
_take
Source
_take.scala
inline def takeEvery[A](inline nTh: Int): ~[A]

Every Nth element filter

Every Nth element filter

Only lets every nTh element

  (1 <> 20).~.takeEvery(4).tp   // Prints: ~(4, 8, 12, 16, 20)
Inherited from
_take
Source
_take.scala
inline def takeFirst[A](n: Int): ~[A]

Head filter

Head filter

Only takes given number of first elements

  (1 <> 10).~.takeFirst(3).tp  // Prints  ~(1, 2, 3)
Inherited from
_take
Source
_take.scala
inline def takeIndexed[A](inline f: (Int, A) => Boolean, inline start: Int): ~[A]

Indexed filter

Indexed filter

Only lets elements satisfying the given function, which also accepts element sequential index

  ('a' <> 'z').~.takeIndexed((i, _) => i >= 2 && i <= 7, 1).tp

  // Output
  ~(b, c, d, e, f, g)

Note: By default indexing starts from 0, but starting value can also be explicitly specified.

Inherited from
_take
Source
_take.scala
inline def takeLast[A](inline n: Int): ~[A]

Tail filter

Tail filter

Only takes given number of elements coming last

  (1 <> 10).~.takeLast(3).tp  // Prints  ~(8, 9, 10)

Note: This method will block on unlimited streams

Inherited from
_take
Source
_take.scala
def takeOnly[A](v: A, vs: A*): ~[A]

Single value filter

Single value filter

Filters only specified value.

  (0 <>> 10).~.takeOnly(5).tp

  // Output
  ~(5)

Note: takeOnly is more efficient than general filter, because there is no function involved.

Inherited from
_take
Source
_take.scala
def takeOnlyBy[A](f: A => B, v: B*): ~[A]
Inherited from
_take
Source
_take.scala
inline def takeType[A](using inline t: scala.reflect.ClassTag[B]): ~[B]

Type filter

Type filter

Only lets elements of specified type

  ~~(1, '2', "3", new Object(), 0.0).takeType[String].tp  // Prints: ~(3)
Inherited from
_take
Source
_take.scala
inline def takeWhile[A](inline f: A => Boolean): ~[A]

Conditional head filter

Conditional head filter

Only takes first consecutive elements satisfying the condition

  def stream = (1 <> 5).~ ++ (1 <> 5)

  stream.tp                     // Prints ~(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)

  stream.takeWhile(_ <= 3).tp    // Prints ~(1, 2, 3)

Note: Everything starting from the first non compliant element will be discarded (including later compliant elements)

Inherited from
_take
Source
_take.scala
inline def transpose[A](using inline f: A => ~[B]): ~[~[B]]

Transpose

Transpose

Transposes matrix where rows become columns

 def stream : ~[~[Int]] = ~~(11 <> 15,
                             List(21, 22, 23, 24, 25),
                             Vector(31, 32, 33, 34, 35))

 stream.print

 stream.transpose.print

 // Output
 ---------------------
 ?
 ---------------------
 ~(11, 12, 13, 14, 15)
 ~(21, 22, 23, 24, 25)
 ~(31, 32, 33, 34, 35)
 ---------------------

 -------------
 ?
 -------------
 ~(11, 21, 31)
 ~(12, 22, 32)
 ~(13, 23, 33)
 ~(14, 24, 34)
 ~(15, 25, 35)
 -------------
Inherited from
_mutate
Source
_mutate.scala
inline def unfold[A](f: ~[A] => Opt[A]): ~[A]

Lazy generator

Lazy generator

Lazily unfolds next stream value with a function taking all prior values

If the given function returns void option, the stream ends

 // Unfolding Fibonacci Sequence

 (0 <> 1).~.unfold(_.takeLast(2).sum).takeFirst(20).tp

 // Output
 ~(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181)

Note: Method .takeFirst(20) is needed, because otherwise the stream will never end and would be hard to print out

Inherited from
_extend
Source
_extend.scala
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)
Inherited from
_zip
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

Inherited from
_zip
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

Inherited from
_zip
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
Inherited from
_zip
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

Inherited from
_zip
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

Inherited from
_zip
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))
Inherited from
_zip
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(\/)))
Inherited from
_zip
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))
Inherited from
_zip
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))
Inherited from
_zip
Source
_zip.scala