# Alasca: Streams

Published on 2018-10-01.
object Stream
fun of[T](...)

value Stream[C, T]
// Simple Transformations
fun map         (f: T => R)        : Stream[C, R]

// Filtering Transformations
fun get         (index: Int)       : Stream[Id, T]
fun first                          : Stream[Id, T]
fun last                           : Stream[Id, T]
fun take        (amount: Int)      : Stream[C, T]
fun takeWhile   (p: T => Boolean)  : Stream[C, T]
fun drop        (amount: Int)      : Stream[C, T]
fun dropWhile   (p: T => Boolean)  : Stream[C, T]
fun accept      (p: T => Boolean)  : Stream[C, T]
fun reject      (p: T => Boolean)  : Stream[C, T]
fun distinct                       : Stream[C, T]

// Folding Transformations
fun fold        (f: (T, T) => R,
start: R)         : Stream[Id, R]
fun reduce      (f: (T, T) => R)   : Stream[Id, R]
fun combine[T: Monoid]             : Stream[Id, R]
fun sum    [T: Numeric]            : Stream[Id, T]
fun product[T: Numeric]            : Stream[Id, T]
fun average[T: Numeric]            : Stream[Id, T]
fun forAll      (p: T => Boolean)  : Stream[Id, Boolean]
fun forAny      (p: T => Boolean)  : Stream[Id, Boolean]
fun forNone     (p: T => Boolean)  : Stream[Id, Boolean]

// Fan-in Transformations
fun concat      (s: Stream[C1, T]) : Stream[C, T]
fun interleave  (s: Stream[C1, T1]): Stream[C, <lub[T, T1]>]
fun zip         (s: Stream[C1, T1]): Stream[C, (T, T1)]
fun zipWithIndex                   : Stream[C, (T, Int)]

// Injecting Transformations
fun joinInner[T : Record]
(s: Stream[C1, T1 : Record])   : Stream[C, concat[recordOf[T], recordOf[T1]]]
fun joinLeft[T : Record]
(s: Stream[C1, T1 : Record])   : Stream[C, concat[recordOf[T], recordOf[T1]]]
fun joinRight[T : Record]
(s: Stream[C1, T1 : Record])   : Stream[C, concat[recordOf[T], recordOf[T1]]]
fun joinOuter[T : Record]
(s: Stream[C1, T1 : Record])   : Stream[C, concat[recordOf[T], recordOf[T1]]]
fun groupBy     (f: T => R)        : Stream[C, Stream[R]]
fun partitionBy
// Flattening Transformations
fun flatten[T : Flattenable]       : Strean[C, T]
fun flatMap     (f: T => Option[R]): Stream[C, R]

// traverse?

value CollectionStream[C <: Collection, T] extends Stream[C, T]
fun run         ()                 : C[T]