sequence

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Range

func Range(size, batch int) []int

Range returns a specific slice for range iteration on another slice.

batch, entities := 100, entity.Fetch() // []entity.Model
for step, end := range sequence.Range(len(entities), batch) {
	service.Process(entities[batch*step:end])
}

func Simple

func Simple(size int) []struct{}

Simple returns an empty slice with the specified size.

for range Simple(5) {
	// do something five times
}

Read the https://dave.cheney.net/2014/03/25/the-empty-struct and the https://github.com/bradfitz/iter.

Types

type Reducer

type Reducer interface {
	// Average returns an average value of the sequence.
	Average() float64
	// Length returns the sequence length.
	Length() int
	// Maximum returns a maximum value of the sequence.
	Maximum() int
	// Median returns a median value of the sequence.
	Median() float64
	// Minimum returns a minimum value of the sequence.
	Minimum() int
	// Sum returns a sum of the sequence.
	Sum() int
}

Reducer defines behavior of a generic reducer above a numeric sequence.

func ReduceInts

func ReduceInts(sequence ...int) Reducer

ReduceInts wraps sequence of integers to perform aggregate operations above it.

ticket, err := semaphore.Acquire(ctx, sequence.ReduceInts(places...).Sum())

if err != nil {
	...
}
defer semaphore.Release(ticket)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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