Documentation ¶
Overview ¶
Package st provides a stream toolkit.
Example ¶
package main import ( "fmt" "gitee.com/lite89/st" ) func main() { var xs *st.Stream[float64] xs = st.New(1, func() *st.Stream[float64] { return st.Zip(xs, xs.Tail(), func(x, y float64) (float64, error) { return x + y, nil }) }).Prepend(0) xs.Take(6).Each(func(i int, x float64) error { fmt.Println(i, x) return nil }) }
Output: 0 0 1 1 2 1 3 2 4 3 5 5
Index ¶
- Variables
- func Fold[V, X any](xs *Stream[X], v V, f func(V, X) V) (V, error)
- func ToDict[K comparable, X any](xs *Stream[X], f func(X) K) (map[K]X, error)
- func ToError[X any](xs *Stream[X]) error
- func ToFunc[X any](xs *Stream[X]) func() (X, error)
- func ToList[X any](xs *Stream[X]) ([]X, error)
- type Complex
- type Float
- type Integer
- type Number
- type Real
- type Result
- func (a *Result[K, X]) Avg(f func(X) float64) float64
- func (a *Result[K, X]) Count() int
- func (a *Result[K, X]) Max(f func(X) float64) float64
- func (a *Result[K, X]) Median(f func(X) float64) float64
- func (a *Result[K, X]) Min(f func(X) float64) float64
- func (a *Result[K, X]) Std(f func(X) float64) float64
- func (a *Result[K, X]) Sum(f func(X) float64) float64
- func (a *Result[K, X]) Var(f func(X) float64) float64
- type Signed
- type Stream
- func Concat[X any](xs *Stream[X], xss ...*Stream[X]) *Stream[X]
- func CrossJoin[X, Y, Z any](xs *Stream[X], ys *Stream[Y], f func(X, Y) Z) *Stream[Z]
- func Distinct[X comparable](xs *Stream[X]) *Stream[X]
- func Filter[X any](xs *Stream[X], f func(X) bool) *Stream[X]
- func Flat[X any](xss *Stream[[]X]) *Stream[X]
- func FromDict[K comparable, X any](dict map[K]X) *Stream[X]
- func FromError[X any](err error) *Stream[X]
- func FromFunc[X any](f func() (X, error)) *Stream[X]
- func FromList[X any](list []X) *Stream[X]
- func Group[K comparable, X any](xs *Stream[X], f func(X) K) *Stream[*Result[K, X]]
- func LeftJoin[K comparable, X, Y, Z any](xs *Stream[X], ys *Stream[Y], xk func(X) K, yk func(Y) K, ...) *Stream[Z]
- func Make[X any](xs ...X) *Stream[X]
- func Map[X, Y any](xs *Stream[X], f func(X) (Y, error)) *Stream[Y]
- func New[X any](head X, builder func() *Stream[X]) *Stream[X]
- func Range[X Real](a, b, s X) *Stream[X]
- func Repeat[X any](x X) *Stream[X]
- func RightJoin[K comparable, X, Y, Z any](xs *Stream[X], ys *Stream[Y], xk func(X) K, yk func(Y) K, ...) *Stream[Z]
- func Sequence[X Number](a, s X) *Stream[X]
- func Zip[X, Y, Z any](xs *Stream[X], ys *Stream[Y], f func(X, Y) (Z, error)) *Stream[Z]
- func (a *Stream[X]) All(f func(X) bool) (bool, error)
- func (a *Stream[X]) Any(f func(X) bool) (bool, error)
- func (a *Stream[X]) Append(xs ...X) *Stream[X]
- func (a *Stream[X]) Concat(xss ...*Stream[X]) *Stream[X]
- func (a *Stream[X]) Count() (int, error)
- func (a *Stream[X]) Drop(n int) *Stream[X]
- func (a *Stream[X]) DropWhile(f func(X) bool) *Stream[X]
- func (a *Stream[X]) Each(f func(int, X) error) error
- func (a *Stream[X]) Filter(f func(X) bool) *Stream[X]
- func (a *Stream[X]) Fold(v X, f func(X, X) X) (X, error)
- func (a *Stream[X]) Force() *Stream[X]
- func (a *Stream[X]) Head() (head X, err error)
- func (a *Stream[X]) IsEmpty() bool
- func (a *Stream[X]) Map(f func(X) (X, error)) *Stream[X]
- func (a *Stream[X]) Prepend(xs ...X) *Stream[X]
- func (a *Stream[X]) Single(defaults ...X) (x X, err error)
- func (a *Stream[X]) Skip(n int) *Stream[X]
- func (a *Stream[X]) SkipWhile(f func(X) bool) *Stream[X]
- func (a *Stream[X]) Sort(f func(x, y X) bool) *Stream[X]
- func (a *Stream[X]) Tail() *Stream[X]
- func (a *Stream[X]) Take(n int) *Stream[X]
- func (a *Stream[X]) TakeWhile(f func(X) bool) *Stream[X]
- func (a *Stream[X]) ToError() error
- func (a *Stream[X]) ToFunc() func() (X, error)
- func (a *Stream[X]) ToList() ([]X, error)
- type Unsigned
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrStop = errors.New("st: stop") ErrEmpty = errors.New("st: empty") ErrNotSingle = errors.New("st: not single") )
Errors.
Functions ¶
func ToDict ¶
func ToDict[K comparable, X any](xs *Stream[X], f func(X) K) (map[K]X, error)
ToDict converts the stream to dict.
Types ¶
type Complex ¶
type Complex interface { ~complex64 | ~complex128 }
Complex is a constraint that permits any complex numeric type.
type Result ¶
type Result[K comparable, X any] struct { Key K Values []X }
Result represents a group result.
type Stream ¶
type Stream[X any] struct { // contains filtered or unexported fields }
Stream represents a stream data structure.
func Distinct ¶
func Distinct[X comparable](xs *Stream[X]) *Stream[X]
Distinct returns a distinct stream.
func FromDict ¶
func FromDict[K comparable, X any](dict map[K]X) *Stream[X]
FromDict creates a stream from dict.
func Group ¶
func Group[K comparable, X any](xs *Stream[X], f func(X) K) *Stream[*Result[K, X]]
Group groups the elements.
func LeftJoin ¶
func LeftJoin[K comparable, X, Y, Z any](xs *Stream[X], ys *Stream[Y], xk func(X) K, yk func(Y) K, f func(K, X, Y) (Z, error)) *Stream[Z]
LeftJoin does left join.
func RightJoin ¶
func RightJoin[K comparable, X, Y, Z any](xs *Stream[X], ys *Stream[Y], xk func(X) K, yk func(Y) K, f func(K, X, Y) (Z, error)) *Stream[Z]
RightJoin does right join.
func (*Stream[X]) DropWhile ¶
DropWhile drops last elements of the stream as long as f returns true.
func (*Stream[X]) SkipWhile ¶
SkipWhile skips first elements of the stream as long as f returns true.
func (*Stream[X]) TakeWhile ¶
TakeWhile takes first elements of the stream as long as f returns true.
Click to show internal directories.
Click to hide internal directories.