_calculate

trait _calculate[A]
class java.lang.Object
trait scala.Matchable
class Any
trait _use
object Stream

Def

inline def average(using v: Math.Average[A]): A

Average

Average

Computes average

For empty Stream returns zero value

   (10 <> 15).stream.map(_.toFloat).average  // Returns 12.5

Note: average is available for types providing given Math.Average implementations, which are by default Double, Float and opaque numerals based on Double and Float

Source
_calculate.scala
inline def averageFew[B,C,D,E,F](fb: A => Opt[B], fc: A => Opt[C], fd: A => Opt[D], fe: A => Opt[E], ff: A => Opt[F])(using nb: Math.Average[B], nc: Math.Average[C], nd: Math.Average[D], ne: Math.Average[E], nf: Math.Average[F]): (B, C) | (B, C, D) | (B, C, D, E) | (B, C, D, E, F)

Multi average

Multi average

Simultaneously computes up to 5 average values for properties specified by functions

Returns tuple of appropriate size with values corresponding to the given mappings

For empty Stream returned tuple will hold zeros

   (1 <> 1000).stream.averageFew(_ * 10F, _ * 100F).tp  // Prints (5005, 50050)

    val (first, second, third) = (1 <> 1000).stream.averageFew(v => v.toDouble, _ * 10.0, _ * 100.0)

    first.tp     // Prints 500.5
    second.tp    // Prints 5005.0
    third.tp     // Prints 50050.0

Note: Averages areavailable for types providing given Stream.Custom.Average implementations, which are by default Double, Float and opaque numerals based on Double and Float

Source
_calculate.scala
inline def averageOpt(using v: Math.Average[A]): Opt[A]

Average option

Average option

Computes average or returns void option for empty stream

   (10 <> 15).stream.map(_.toFloat).averageOpt  // Returns Opt(12.5)

Note: averageOpt is available for types providing given Math.Average implementations, which are by default Double, Float and opaque numerals based on Double and Float

Source
_calculate.scala
inline def max(using o: Ordering[A]): A

Maximum

Maximum

Computes maximum value

Fails for empty streams

Source
_calculate.scala
inline def maxBy[B](f: A => B)(using o: Ordering[B]): A

Maximum by property

Maximum by property

Computes maximum value based on given function

Fails for empty streams

Source
_calculate.scala
inline def maxByOpt(f: A => B)(using o: Ordering[B]): Opt[A]

Optional maximum by property

Optional maximum by property

Computes maximum value based on given function or returns void option for empty streams

Source
_calculate.scala
inline def maxOpt(using o: Ordering[A]): Opt[A]

Optional maximum

Optional maximum

Computes maximum value or returns void option for empty streams

Source
_calculate.scala
inline def min(using o: Ordering[A]): A

Minimum

Minimum

Computes minimum value

Fails for empty streams

Source
_calculate.scala
inline def minBy[B](f: A => B)(using o: Ordering[B]): A

Minimum by property

Minimum by property

Computes minimum value based on given function

Fails for empty streams

Source
_calculate.scala
inline def minByOpt(f: A => B)(using o: Ordering[B]): Opt[A]

Optional minimum by property

Optional minimum by property

Computes minimum value based on given function or returns void option for empty streams

Source
_calculate.scala
inline def minOpt(using o: Ordering[A]): Opt[A]

Optional minimum

Optional minimum

Computes minimum value or returns void option for empty streams

Source
_calculate.scala
inline def range(using o: Ordering[A]): Range[A]

Range

Range

Computes value range

Fails for empty streams

Source
_calculate.scala
inline def rangeOpt(using o: Ordering[A]): Opt[Range[A]]

Optional range

Optional range

Computes value value or returns void option for empty streams

Source
_calculate.scala
inline def sum(using v: Math.Sum[A]): A

Sum

Sum

Calculates sum of all values

For empty stream returns zero

    (1 <> 1000).stream.sum.tp // Prints 500500
Source
_calculate.scala
inline def sumFew[B,C,D,E,F](fb: A => Opt[B], fc: A => Opt[C], fd: A => Opt[D], fe: A => Opt[E], ff: A => Opt[F])(using nb: Math.Sum[B], nc: Math.Sum[C], nd: Math.Sum[D], ne: Math.Sum[E], nf: Math.Sum[F]): (B, C) | (B, C, D) | (B, C, D, E) | (B, C, D, E, F)

Multi sum

Multi sum

Simultaneously computes up to 5 sum values for properties specified by given functions

Returns tuple of appropriate size with values corresponding to the given mappings

For empty Stream returned tuple will hold zeros

 (1 <> 1000).stream.sumFew(_ * 10, _ * 100).tp  // Prints (5005000, 50050000)

 val (first, second, third) = (1 <> 1000).stream.sumFew(v => v, _ * 10, _ * 100)

 first.tp     // Prints 500500
 second.tp    // Prints 5005000
 third.tp     // Prints 50050000
Source
_calculate.scala
inline def sumOpt(using v: Math.Sum[A]): Opt[A]

Optional sum

Optional sum

Calculates sum of all values or returns void option for empty streams

    (1 <> 1000).stream.sumOpt.tp // Prints Opt(500500)
Source
_calculate.scala