lazystream

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 6 Imported by: 0

README

lazy-stream

Lazy-Stream is a lightweight, functional, lazy streaming library for Go built with generics. It provides composable operations like Map, Filter, Reduce, and more, enabling declarative, pipeline-style data processing on slices and channels inspired by functional programming paradigms.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Identity

func Identity[T any](v T) T

func Reduce

func Reduce[T, R any](s *Stream[T], reducer func(R, T) R, initial R) R

NOTE: Fix when MethodGenerics are supported

Types

type Pair

type Pair[T, U any] struct {
	Left  T
	Right U
}

func (*Pair[T, U]) Splat

func (pair *Pair[T, U]) Splat() (T, U)

type Stream

type Stream[T any] struct {
	// contains filtered or unexported fields
}

func Batched

func Batched[T any](s *Stream[T], n int) *Stream[[]T]

func Chunked

func Chunked[T any](s *Stream[T], predicate func(T) bool) *Stream[[]T]

func Count

func Count(start int, step int) *Stream[int]

func Cycle

func Cycle[T any](data []T) *Stream[T]

func DistinctBy

func DistinctBy[T any, R comparable](s *Stream[T], keyFunc func(T) R) *Stream[T]

func FlatMap

func FlatMap[T, R any](s *Stream[T], mapper func(T) []R) *Stream[R]

func Flatten

func Flatten[T any](s *Stream[[]T]) *Stream[T]

func FromChannel

func FromChannel[T any](ch <-chan T) *Stream[T]

func FromFile

func FromFile(path string) *Stream[string]

func FromSeq

func FromSeq[T any](seq iter.Seq[T]) *Stream[T]

func FromSlice

func FromSlice[T any](data []T) *Stream[T]

func FromStdin

func FromStdin() *Stream[string]

func GroupBy

func GroupBy[T any](s *Stream[T], keyFunc func(T) T) *Stream[[]T]

func Map

func Map[T, R any](s *Stream[T], mapper func(T) R) *Stream[R]

func PairWise

func PairWise[T any](s *Stream[T]) *Stream[Pair[T, T]]

func Range

func Range(start, end, step int) *Stream[int]

func Repeat

func Repeat[T any](elem T, n int) *Stream[T]

func Sort

func Sort[T cmp.Ordered](s *Stream[T]) *Stream[T]

func ToPairStream

func ToPairStream[K, V any](s *Stream2[K, V]) *Stream[Pair[K, V]]

func Unique

func Unique[T any, R comparable](s *Stream[T], keyFunc func(T) R) *Stream[T]

func ZipLongest

func ZipLongest[T any](s *Stream[T], other *Stream[T], fillValue T) *Stream[[]T]

ZipLongest returns a new Stream where each element is a slice containing elements from the original stream and the provided 'other' stream. If the streams are of unequal length, the shorter stream will be padded with 'fillValue' until both streams are exhausted.

func (*Stream[T]) Accumulate

func (s *Stream[T]) Accumulate(fn func(T, T) T) *Stream[T]

func (*Stream[T]) All

func (s *Stream[T]) All(predicate func(T) bool) bool

func (*Stream[T]) Any

func (s *Stream[T]) Any(predicate func(T) bool) bool

func (*Stream[T]) Append

func (s *Stream[T]) Append(items ...T) *Stream[T]

func (*Stream[T]) Cache

func (s *Stream[T]) Cache() *Stream[T]

| `cache()` | Forces evaluation of sequence immediately and caches the result | action |

func (*Stream[T]) Chain

func (s *Stream[T]) Chain(args ...*Stream[T]) *Stream[T]

func (*Stream[T]) Compress

func (s *Stream[T]) Compress(d *Stream[bool]) *Stream[T]

func (*Stream[T]) Count

func (s *Stream[T]) Count(predicate func(T) bool) int

func (*Stream[T]) Cycle

func (s *Stream[T]) Cycle() *Stream[T]

func (*Stream[T]) Drop

func (s *Stream[T]) Drop(n int) *Stream[T]

| `drop(n)` | Drops the first `n` elements of the sequence | transformation |

func (*Stream[T]) DropWhile

func (s *Stream[T]) DropWhile(predicate func(T) bool) *Stream[T]

func (*Stream[T]) Enumerate

func (s *Stream[T]) Enumerate() *Stream2[int, T]

func (*Stream[T]) Exists

func (s *Stream[T]) Exists(predicate func(T) bool) bool

func (*Stream[T]) Filter

func (s *Stream[T]) Filter(predicate func(T) bool) *Stream[T]

func (*Stream[T]) FilterFalse

func (s *Stream[T]) FilterFalse(predicate func(T) bool) *Stream[T]

func (*Stream[T]) Find

func (s *Stream[T]) Find(predicate func(T) bool) (T, bool)

func (*Stream[T]) ForEach

func (s *Stream[T]) ForEach(action func(T))

| `for_each(func)` | Executes `func` on each element of the sequence | action |

func (*Stream[T]) Head

func (s *Stream[T]) Head() T

func (*Stream[T]) ISlice

func (s *Stream[T]) ISlice(start int, stop int) *Stream[T]

func (*Stream[T]) Init

func (s *Stream[T]) Init() *Stream[T]

func (*Stream[T]) Iter added in v0.0.3

func (s *Stream[T]) Iter() iter.Seq[T]

func (*Stream[T]) Join

func (s *Stream[T]) Join(separator string) string

func (*Stream[T]) Last

func (s *Stream[T]) Last() T

func (*Stream[T]) Len

func (s *Stream[T]) Len() int

func (*Stream[T]) List

func (s *Stream[T]) List() []T

func (*Stream[T]) MakeString

func (s *Stream[T]) MakeString(separator string) string

| `make_string(separator)` | Returns string with `separator` between each `str(element)` | action |

func (*Stream[T]) MapBool

func (s *Stream[T]) MapBool(mapper func(T) bool) *Stream[bool]

func (*Stream[T]) MapByte

func (s *Stream[T]) MapByte(mapper func(T) byte) *Stream[byte]

func (*Stream[T]) MapComplex128

func (s *Stream[T]) MapComplex128(mapper func(T) complex128) *Stream[complex128]

func (*Stream[T]) MapComplex64

func (s *Stream[T]) MapComplex64(mapper func(T) complex64) *Stream[complex64]

func (*Stream[T]) MapError

func (s *Stream[T]) MapError(mapper func(T) error) *Stream[error]

func (*Stream[T]) MapFloat32

func (s *Stream[T]) MapFloat32(mapper func(T) float32) *Stream[float32]

func (*Stream[T]) MapFloat64

func (s *Stream[T]) MapFloat64(mapper func(T) float64) *Stream[float64]

func (*Stream[T]) MapInt

func (s *Stream[T]) MapInt(mapper func(T) int) *Stream[int]

func (*Stream[T]) MapInt16

func (s *Stream[T]) MapInt16(mapper func(T) int16) *Stream[int16]

func (*Stream[T]) MapInt32

func (s *Stream[T]) MapInt32(mapper func(T) int32) *Stream[int32]

func (*Stream[T]) MapInt64

func (s *Stream[T]) MapInt64(mapper func(T) int64) *Stream[int64]

func (*Stream[T]) MapInt8

func (s *Stream[T]) MapInt8(mapper func(T) int8) *Stream[int8]

func (*Stream[T]) MapRune

func (s *Stream[T]) MapRune(mapper func(T) rune) *Stream[rune]

func (*Stream[T]) MapString

func (s *Stream[T]) MapString(mapper func(T) string) *Stream[string]

func (*Stream[T]) MapT

func (s *Stream[T]) MapT(mapper func(T) T) *Stream[T]

func (*Stream[T]) MapUint

func (s *Stream[T]) MapUint(mapper func(T) uint) *Stream[uint]

func (*Stream[T]) MapUint16

func (s *Stream[T]) MapUint16(mapper func(T) uint16) *Stream[uint16]

func (*Stream[T]) MapUint32

func (s *Stream[T]) MapUint32(mapper func(T) uint32) *Stream[uint32]

func (*Stream[T]) MapUint64

func (s *Stream[T]) MapUint64(mapper func(T) uint64) *Stream[uint64]

func (*Stream[T]) MapUint8

func (s *Stream[T]) MapUint8(mapper func(T) uint8) *Stream[uint8]

func (*Stream[T]) MapUintptr

func (s *Stream[T]) MapUintptr(mapper func(T) uintptr) *Stream[uintptr]

func (*Stream[T]) Max

func (s *Stream[T]) Max(comparator func(T, T) int) T

func (*Stream[T]) Min

func (s *Stream[T]) Min(comparator func(T, T) int) T

func (*Stream[T]) Peek

func (s *Stream[T]) Peek(action func(T)) *Stream[T]

| `peek(func)` | Executes `func` on each element of the sequence and returns it | transformation |****

func (*Stream[T]) Prepend

func (s *Stream[T]) Prepend(items ...T) *Stream[T]

func (*Stream[T]) Reduce

func (s *Stream[T]) Reduce(reducer func(T, T) T, initial T) T

func (*Stream[T]) Reversed

func (s *Stream[T]) Reversed() *Stream[T]

func (*Stream[T]) Slice

func (s *Stream[T]) Slice(start, stop, step int) *Stream[T]

func (*Stream[T]) Sorted

func (s *Stream[T]) Sorted(cmp func(T, T) int) *Stream[T]

func (*Stream[T]) SortedStable

func (s *Stream[T]) SortedStable(cmp func(T, T) int) *Stream[T]

func (*Stream[T]) Sum

func (s *Stream[T]) Sum(addFunc func(T, T) T) T

func (*Stream[T]) Tail

func (s *Stream[T]) Tail() *Stream[T]

func (*Stream[T]) Take

func (s *Stream[T]) Take(n int) *Stream[T]

| `take(n)` | Returns sequence of first `n` elements | transformation |

func (*Stream[T]) TakeWhile

func (s *Stream[T]) TakeWhile(predicate func(T) bool) *Stream[T]

TakeWhile returns a new Stream that yields items from the original Stream as long as the provided predicate function returns true. Once the predicate function returns false, the Stream stops yielding items.

The predicate function takes an item of type T and returns a boolean indicating whether the item should be included in the resulting Stream.

Example usage:

stream := NewStream([]int{1, 2, 3, 4, 5})
result := stream.TakeWhile(func(n int) bool { return n < 4 })
// result will yield 1, 2, 3

Parameters:

predicate - A function that takes an item of type T and returns a boolean.

Returns:

A new Stream that yields items from the original Stream as long as the
predicate function returns true.

func (*Stream[T]) ToChannel

func (s *Stream[T]) ToChannel() chan T

func (*Stream[T]) Uncons

func (s *Stream[T]) Uncons() (T, *Stream[T])

func (*Stream[T]) Unsnoc

func (s *Stream[T]) Unsnoc() (*Stream[T], T)

type Stream2

type Stream2[K, V any] struct {
	// contains filtered or unexported fields
}

func Zip

func Zip[K, V any](s1 *Stream[K], s2 *Stream[V]) *Stream2[K, V]

type Triplet

type Triplet[A, B, C any] struct {
	Left   A
	Middle B
	Right  C
}

func (*Triplet[A, B, C]) Splat

func (triplet *Triplet[A, B, C]) Splat() (A, B, C)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL