Documentation ¶
Index ¶
- type Indexed
- type IterResult
- func CollectAll[T any](ctx context.Context, it TryNextor[T]) IterResult[[]T]
- func CollectMany[T any](ctx context.Context, it TryNextor[T], n uint) IterResult[[]T]
- func Done[T any]() IterResult[T]
- func DoneBy[T, O any](r IterResult[O]) IterResult[T]
- func Emit[T any](t T) IterResult[T]
- func Throw[T any](err error) IterResult[T]
- type TransformConfig
- type TryNextor
- func ConcatAll[T any](items ...TryNextor[T]) TryNextor[T]
- func Enumerate[T any](it TryNextor[T]) TryNextor[Indexed[T]]
- func Fail[T any](err error) TryNextor[T]
- func FilterOut[T any](it TryNextor[T], f func(T) bool) TryNextor[T]
- func FlatMap[T, R any](it TryNextor[T], mapper func(T) TryNextor[R]) TryNextor[R]
- func FromSlice[T any](s []T) TryNextor[T]
- func Func[T any](g func(ctx context.Context) IterResult[T]) TryNextor[T]
- func Map[T, R any](it TryNextor[T], mapper func(T) R) TryNextor[R]
- func OfRange[T constraints.Integer](begin, end T) TryNextor[T]
- func TakeFirst[T any](inner TryNextor[T], n uint) TryNextor[T]
- func Tap[T any](i TryNextor[T], with func(T)) TryNextor[T]
- func Transform[T, R any](it TryNextor[T], with func(context.Context, T) (R, error), ...) TryNextor[R]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IterResult ¶
IterResult is the result of try to advancing an impure iterator. Generally it is a "sum type", which only one field would be filled. You can create it via `Done`, `Emit` and `Throw`.
func CollectAll ¶
func CollectAll[T any](ctx context.Context, it TryNextor[T]) IterResult[[]T]
CollectAll fully consumes the iterator, collecting all items the iterator emitted. When the iterator has been finished, it emits empty slice and won't set `Finished`.
func CollectMany ¶
CollectMany collects the first n items of the iterator. When the iterator contains less data than N, it emits as many items as it can and won't set `Finished`.
func Done ¶
func Done[T any]() IterResult[T]
Done creates an IterResult which indices the iteration has finished.
func DoneBy ¶
func DoneBy[T, O any](r IterResult[O]) IterResult[T]
DoneBy creates a finished or error IterResult by its argument.
func Emit ¶
func Emit[T any](t T) IterResult[T]
Emit creates an IterResult which contains normal data.
func Throw ¶
func Throw[T any](err error) IterResult[T]
Throw creates an IterResult which contains the err.
func (IterResult[T]) FinishedOrError ¶
func (r IterResult[T]) FinishedOrError() bool
func (IterResult[T]) String ¶
func (r IterResult[T]) String() string
type TransformConfig ¶
type TransformConfig func(*chunkMappingCfg)
TransformConfig is the config for the combinator "transform".
func WithChunkSize ¶
func WithChunkSize(n uint) TransformConfig
func WithConcurrency ¶
func WithConcurrency(n uint) TransformConfig
type TryNextor ¶
type TryNextor[T any] interface { TryNext(ctx context.Context) IterResult[T] }
TryNextor is the general interface for "impure" iterators: which may trigger some error or block the caller when advancing.
func ConcatAll ¶
ConcatAll concatenates all elements yields by the iterators. In another word, it 'chains' all the input iterators.
func FilterOut ¶
FilterOut returns an iterator that yields all elements the original iterator generated and DOESN'T satisfies the predicate.
func FlatMap ¶
FlapMap applies the mapper over every elements the origin iterator generates, then flatten them.
func Func ¶
func Func[T any](g func(ctx context.Context) IterResult[T]) TryNextor[T]
Func generates results by a function.
func OfRange ¶
func OfRange[T constraints.Integer](begin, end T) TryNextor[T]
OfRange creates an iterator that yields elements in the integer range.
func Tap ¶
Tap adds a hook into the iterator, it would execute the function anytime the iterator emits an item.
func Transform ¶
func Transform[T, R any](it TryNextor[T], with func(context.Context, T) (R, error), cs ...TransformConfig) TryNextor[R]
Transform returns an iterator that performs an impure procedure for each element, then emitting the result of that procedure. The execution of that procedure can be paralleled with the config `WithConcurrency`. You may also need to config the `WithChunkSize`, because the concurrent execution is only available intra-batch.