_extend

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

Def

@targetName("join")
inline def +(v: A): Stream[A]

Alias for join

Alias for join

Creates a new Stream with given element appended to current Stream

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

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

Alias for joinAll

Alias for joinAll

Creates a new Stream with given elements appended to current Stream

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

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

Alias for joinAllAt

Alias for joinAllAt

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

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

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

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

Alias for joinAt

Alias for joinAt

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

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

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

  // Output
  Stream(a, b, X, c, d)
Source
_extend.scala
inline def default(v: => A): Stream[A]

Default element

Default element

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

Otherwise current Stream will not change

 (1 <>> 1).stream.default(99).tp // Prints Stream(99)

 (1 <>> 5).stream.default(99).tp // Prints Stream(1, 2, 3, 4)
Source
_extend.scala
inline def join(v: A): Stream[A]

Join element

Join element

Creates a new Stream with given element appended to current Stream

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

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

Join all

Join all

Creates a new Stream with given elements appended to current Stream

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

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

Join all at position

Join all at position

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

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

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

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

Join element at position

Join element at position

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

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

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

  // Output
  Stream(a, b, X, c, d)
Source
_extend.scala
inline def repeat(times: Int): Stream[A]

Repeat elements

Repeat elements

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

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

 // Output
 Stream(0, 0, 0, 1, 1, 1, 2, 2, 2)
Source
_extend.scala
inline def unfold(f: Stream[A] => Opt[A]): Stream[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).stream.unfold(_.takeLast(2).sum).takeFirst(20).tp

 // Output
 Stream(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

Source
_extend.scala