pie

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: MIT Imports: 6 Imported by: 63

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Float64s

type Float64s []float64

func (Float64s) Abs added in v1.11.0

func (ss Float64s) Abs() Float64s

Abs is a function which returns the absolute value of all the elements in the slice.

func (Float64s) All added in v1.4.0

func (ss Float64s) All(fn func(value float64) bool) bool

All will return true if all callbacks return true. It follows the same logic as the all() function in Python.

If the list is empty then true is always returned.

func (Float64s) Any added in v1.4.0

func (ss Float64s) Any(fn func(value float64) bool) bool

Any will return true if any callbacks return true. It follows the same logic as the any() function in Python.

If the list is empty then false is always returned.

func (Float64s) Append added in v1.3.0

func (ss Float64s) Append(elements ...float64) Float64s

Append will return a new slice with the elements appended to the end. It is a wrapper for the internal append(). It is offered as a function so that it can more easily chained.

It is acceptable to provide zero arguments.

func (Float64s) AreSorted

func (ss Float64s) AreSorted() bool

AreSorted will return true if the slice is already sorted. It is a wrapper for sort.Float64sAreSorted.

func (Float64s) AreUnique

func (ss Float64s) AreUnique() bool

AreUnique will return true if the slice contains elements that are all different (unique) from each other.

func (Float64s) Average

func (ss Float64s) Average() float64

Average is the average of all of the elements, or zero if there are no elements.

func (Float64s) Bottom added in v1.7.0

func (ss Float64s) Bottom(n int) (top Float64s)

Bottom will return n elements from bottom

that means that elements is taken from the end of the slice for this [1,2,3] slice with n == 2 will be returned [3,2] if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (Float64s) Contains

func (ss Float64s) Contains(lookingFor float64) bool

Contains returns true if the element exists in the slice.

When using slices of pointers it will only compare by address, not value.

func (Float64s) Each added in v1.10.0

func (ss Float64s) Each(fn func(float64)) Float64s

Each is more condensed version of Transform that allows an action to happen on each elements and pass the original slice on.

cars.Each(func (car *Car) {
    fmt.Printf("Car color is: %s\n", car.Color)
})

Pie will not ensure immutability on items passed in so they can be manipulated, if you choose to do it this way, for example:

// Set all car colors to Red.
cars.Each(func (car *Car) {
    car.Color = "Red"
})

func (Float64s) Extend added in v1.3.0

func (ss Float64s) Extend(slices ...Float64s) (ss2 Float64s)

Extend will return a new slice with the slices of elements appended to the end.

It is acceptable to provide zero arguments.

func (Float64s) Filter added in v1.14.0

func (ss Float64s) Filter(condition func(float64) bool) (ss2 Float64s)

Filter will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).

FilterNot works in the opposite way of Filter.

func (Float64s) FilterNot added in v1.14.0

func (ss Float64s) FilterNot(condition func(float64) bool) (ss2 Float64s)

FilterNot works the same as Filter, with a negated condition. That is, it will return a new slice only containing the elements that returned false from the condition. The returned slice may contain zero elements (nil).

func (Float64s) First

func (ss Float64s) First() float64

First returns the first element, or zero. Also see FirstOr().

func (Float64s) FirstOr

func (ss Float64s) FirstOr(defaultValue float64) float64

FirstOr returns the first element or a default value if there are no elements.

func (Float64s) Intersect added in v1.15.0

func (ss Float64s) Intersect(slices ...Float64s) (ss2 Float64s)

Intersect returns items that exist in all lists.

It returns slice without any duplicates. If zero slice arguments are provided, then nil is returned.

func (Float64s) JSONString

func (ss Float64s) JSONString() string

JSONString returns the JSON encoded array as a string.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.

func (Float64s) Last

func (ss Float64s) Last() float64

Last returns the last element, or zero. Also see LastOr().

func (Float64s) LastOr

func (ss Float64s) LastOr(defaultValue float64) float64

LastOr returns the last element or a default value if there are no elements.

func (Float64s) Len

func (ss Float64s) Len() int

Len returns the number of elements.

func (Float64s) Map added in v1.14.0

func (ss Float64s) Map(fn func(float64) float64) (ss2 Float64s)

Map will return a new slice where each element has been mapped (transformed). The number of elements returned will always be the same as the input.

Be careful when using this with slices of pointers. If you modify the input value it will affect the original slice. Be sure to return a new allocated object or deep copy the existing one.

func (Float64s) Max

func (ss Float64s) Max() (max float64)

Max is the maximum value, or zero.

func (Float64s) Median added in v1.9.0

func (ss Float64s) Median() float64

Median returns the value separating the higher half from the lower half of a data sample.

Zero is returned if there are no elements in the slice.

func (Float64s) Min

func (ss Float64s) Min() (min float64)

Min is the minimum value, or zero.

func (Float64s) Product added in v1.16.0

func (ss Float64s) Product() (product float64)

Product is the product of all of the elements.

func (Float64s) Random added in v1.12.0

func (ss Float64s) Random(source rand.Source) float64

Random returns a random element by your rand.Source, or zero

func (Float64s) Reduce added in v1.17.0

func (ss Float64s) Reduce(reducer func(float64, float64) float64) (el float64)

Reduce continually applies the provided function over the slice. Reducing the elements to a single value.

Returns a zero value of float64 if there are no elements in the slice. It will panic if the reducer is nil and the slice has more than one element (required to invoke reduce). Otherwise returns result of applying reducer from left to right.

func (Float64s) Reverse

func (ss Float64s) Reverse() Float64s

Reverse returns a new copy of the slice with the elements ordered in reverse. This is useful when combined with Sort to get a descending sort order:

ss.Sort().Reverse()

func (Float64s) Send added in v1.13.0

func (ss Float64s) Send(ctx context.Context, ch chan<- float64) Float64s

Send sends elements to channel in normal act it sends all elements but if func canceled it can be less

it locks execution of gorutine it doesn't close channel after work returns sended elements if len(this) != len(old) considered func was canceled

func (Float64s) Shuffle added in v1.6.0

func (ss Float64s) Shuffle(source rand.Source) Float64s

Shuffle returns shuffled slice by your rand.Source

func (Float64s) Sort

func (ss Float64s) Sort() Float64s

Sort works similar to sort.Float64s(). However, unlike sort.Float64s the slice returned will be reallocated as to not modify the input slice.

See Reverse() and AreSorted().

func (Float64s) Sum

func (ss Float64s) Sum() (sum float64)

Sum is the sum of all of the elements.

func (Float64s) ToStrings added in v1.1.0

func (ss Float64s) ToStrings(transform func(float64) string) Strings

ToStrings transforms each element to a string.

func (Float64s) Top added in v1.7.0

func (ss Float64s) Top(n int) (top Float64s)

Top will return n elements from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (Float64s) Unique

func (ss Float64s) Unique() Float64s

Unique returns a new slice with all of the unique values.

The items will be returned in a randomized order, even with the same input.

The number of items returned may be the same as the input or less. It will never return zero items unless then input slice has zero items.

A slice with zero elements is considered to be unique.

See AreUnique().

type Ints

type Ints []int

func (Ints) Abs added in v1.11.0

func (ss Ints) Abs() Ints

Abs is a function which returns the absolute value of all the elements in the slice.

func (Ints) All added in v1.4.0

func (ss Ints) All(fn func(value int) bool) bool

All will return true if all callbacks return true. It follows the same logic as the all() function in Python.

If the list is empty then true is always returned.

func (Ints) Any added in v1.4.0

func (ss Ints) Any(fn func(value int) bool) bool

Any will return true if any callbacks return true. It follows the same logic as the any() function in Python.

If the list is empty then false is always returned.

func (Ints) Append added in v1.3.0

func (ss Ints) Append(elements ...int) Ints

Append will return a new slice with the elements appended to the end. It is a wrapper for the internal append(). It is offered as a function so that it can more easily chained.

It is acceptable to provide zero arguments.

func (Ints) AreSorted

func (ss Ints) AreSorted() bool

AreSorted will return true if the slice is already sorted. It is a wrapper for sort.IntsAreSorted.

func (Ints) AreUnique

func (ss Ints) AreUnique() bool

AreUnique will return true if the slice contains elements that are all different (unique) from each other.

func (Ints) Average

func (ss Ints) Average() float64

Average is the average of all of the elements, or zero if there are no elements.

func (Ints) Bottom added in v1.7.0

func (ss Ints) Bottom(n int) (top Ints)

Bottom will return n elements from bottom

that means that elements is taken from the end of the slice for this [1,2,3] slice with n == 2 will be returned [3,2] if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (Ints) Contains

func (ss Ints) Contains(lookingFor int) bool

Contains returns true if the element exists in the slice.

When using slices of pointers it will only compare by address, not value.

func (Ints) Each added in v1.10.0

func (ss Ints) Each(fn func(int)) Ints

Each is more condensed version of Transform that allows an action to happen on each elements and pass the original slice on.

cars.Each(func (car *Car) {
    fmt.Printf("Car color is: %s\n", car.Color)
})

Pie will not ensure immutability on items passed in so they can be manipulated, if you choose to do it this way, for example:

// Set all car colors to Red.
cars.Each(func (car *Car) {
    car.Color = "Red"
})

func (Ints) Extend added in v1.3.0

func (ss Ints) Extend(slices ...Ints) (ss2 Ints)

Extend will return a new slice with the slices of elements appended to the end.

It is acceptable to provide zero arguments.

func (Ints) Filter added in v1.14.0

func (ss Ints) Filter(condition func(int) bool) (ss2 Ints)

Filter will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).

FilterNot works in the opposite way of Filter.

func (Ints) FilterNot added in v1.14.0

func (ss Ints) FilterNot(condition func(int) bool) (ss2 Ints)

FilterNot works the same as Filter, with a negated condition. That is, it will return a new slice only containing the elements that returned false from the condition. The returned slice may contain zero elements (nil).

func (Ints) First

func (ss Ints) First() int

First returns the first element, or zero. Also see FirstOr().

func (Ints) FirstOr

func (ss Ints) FirstOr(defaultValue int) int

FirstOr returns the first element or a default value if there are no elements.

func (Ints) Intersect added in v1.15.0

func (ss Ints) Intersect(slices ...Ints) (ss2 Ints)

Intersect returns items that exist in all lists.

It returns slice without any duplicates. If zero slice arguments are provided, then nil is returned.

func (Ints) JSONString

func (ss Ints) JSONString() string

JSONString returns the JSON encoded array as a string.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.

func (Ints) Last

func (ss Ints) Last() int

Last returns the last element, or zero. Also see LastOr().

func (Ints) LastOr

func (ss Ints) LastOr(defaultValue int) int

LastOr returns the last element or a default value if there are no elements.

func (Ints) Len

func (ss Ints) Len() int

Len returns the number of elements.

func (Ints) Map added in v1.14.0

func (ss Ints) Map(fn func(int) int) (ss2 Ints)

Map will return a new slice where each element has been mapped (transformed). The number of elements returned will always be the same as the input.

Be careful when using this with slices of pointers. If you modify the input value it will affect the original slice. Be sure to return a new allocated object or deep copy the existing one.

func (Ints) Max

func (ss Ints) Max() (max int)

Max is the maximum value, or zero.

func (Ints) Median added in v1.9.0

func (ss Ints) Median() int

Median returns the value separating the higher half from the lower half of a data sample.

Zero is returned if there are no elements in the slice.

func (Ints) Min

func (ss Ints) Min() (min int)

Min is the minimum value, or zero.

func (Ints) Product added in v1.16.0

func (ss Ints) Product() (product int)

Product is the product of all of the elements.

func (Ints) Random added in v1.12.0

func (ss Ints) Random(source rand.Source) int

Random returns a random element by your rand.Source, or zero

func (Ints) Reduce added in v1.17.0

func (ss Ints) Reduce(reducer func(int, int) int) (el int)

Reduce continually applies the provided function over the slice. Reducing the elements to a single value.

Returns a zero value of int if there are no elements in the slice. It will panic if the reducer is nil and the slice has more than one element (required to invoke reduce). Otherwise returns result of applying reducer from left to right.

func (Ints) Reverse

func (ss Ints) Reverse() Ints

Reverse returns a new copy of the slice with the elements ordered in reverse. This is useful when combined with Sort to get a descending sort order:

ss.Sort().Reverse()

func (Ints) Send added in v1.13.0

func (ss Ints) Send(ctx context.Context, ch chan<- int) Ints

Send sends elements to channel in normal act it sends all elements but if func canceled it can be less

it locks execution of gorutine it doesn't close channel after work returns sended elements if len(this) != len(old) considered func was canceled

func (Ints) Shuffle added in v1.6.0

func (ss Ints) Shuffle(source rand.Source) Ints

Shuffle returns shuffled slice by your rand.Source

func (Ints) Sort

func (ss Ints) Sort() Ints

Sort works similar to sort.Ints(). However, unlike sort.Ints the slice returned will be reallocated as to not modify the input slice.

See Reverse() and AreSorted().

func (Ints) Sum

func (ss Ints) Sum() (sum int)

Sum is the sum of all of the elements.

func (Ints) ToStrings added in v1.1.0

func (ss Ints) ToStrings(transform func(int) string) Strings

ToStrings transforms each element to a string.

func (Ints) Top added in v1.7.0

func (ss Ints) Top(n int) (top Ints)

Top will return n elements from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (Ints) Unique

func (ss Ints) Unique() Ints

Unique returns a new slice with all of the unique values.

The items will be returned in a randomized order, even with the same input.

The number of items returned may be the same as the input or less. It will never return zero items unless then input slice has zero items.

A slice with zero elements is considered to be unique.

See AreUnique().

type Strings

type Strings []string

func (Strings) All added in v1.4.0

func (ss Strings) All(fn func(value string) bool) bool

All will return true if all callbacks return true. It follows the same logic as the all() function in Python.

If the list is empty then true is always returned.

func (Strings) Any added in v1.4.0

func (ss Strings) Any(fn func(value string) bool) bool

Any will return true if any callbacks return true. It follows the same logic as the any() function in Python.

If the list is empty then false is always returned.

func (Strings) Append added in v1.3.0

func (ss Strings) Append(elements ...string) Strings

Append will return a new slice with the elements appended to the end. It is a wrapper for the internal append(). It is offered as a function so that it can more easily chained.

It is acceptable to provide zero arguments.

func (Strings) AreSorted

func (ss Strings) AreSorted() bool

AreSorted will return true if the slice is already sorted. It is a wrapper for sort.StringsAreSorted.

func (Strings) AreUnique

func (ss Strings) AreUnique() bool

AreUnique will return true if the slice contains elements that are all different (unique) from each other.

func (Strings) Bottom added in v1.7.0

func (ss Strings) Bottom(n int) (top Strings)

Bottom will return n elements from bottom

that means that elements is taken from the end of the slice for this [1,2,3] slice with n == 2 will be returned [3,2] if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (Strings) Contains

func (ss Strings) Contains(lookingFor string) bool

Contains returns true if the element exists in the slice.

When using slices of pointers it will only compare by address, not value.

func (Strings) Each added in v1.10.0

func (ss Strings) Each(fn func(string)) Strings

Each is more condensed version of Transform that allows an action to happen on each elements and pass the original slice on.

cars.Each(func (car *Car) {
    fmt.Printf("Car color is: %s\n", car.Color)
})

Pie will not ensure immutability on items passed in so they can be manipulated, if you choose to do it this way, for example:

// Set all car colors to Red.
cars.Each(func (car *Car) {
    car.Color = "Red"
})

func (Strings) Extend added in v1.3.0

func (ss Strings) Extend(slices ...Strings) (ss2 Strings)

Extend will return a new slice with the slices of elements appended to the end.

It is acceptable to provide zero arguments.

func (Strings) Filter added in v1.14.0

func (ss Strings) Filter(condition func(string) bool) (ss2 Strings)

Filter will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).

FilterNot works in the opposite way of Filter.

func (Strings) FilterNot added in v1.14.0

func (ss Strings) FilterNot(condition func(string) bool) (ss2 Strings)

FilterNot works the same as Filter, with a negated condition. That is, it will return a new slice only containing the elements that returned false from the condition. The returned slice may contain zero elements (nil).

func (Strings) First

func (ss Strings) First() string

First returns the first element, or zero. Also see FirstOr().

func (Strings) FirstOr

func (ss Strings) FirstOr(defaultValue string) string

FirstOr returns the first element or a default value if there are no elements.

func (Strings) Intersect added in v1.15.0

func (ss Strings) Intersect(slices ...Strings) (ss2 Strings)

Intersect returns items that exist in all lists.

It returns slice without any duplicates. If zero slice arguments are provided, then nil is returned.

func (Strings) JSONString

func (ss Strings) JSONString() string

JSONString returns the JSON encoded array as a string.

One important thing to note is that it will treat a nil slice as an empty slice to ensure that the JSON value return is always an array.

func (Strings) Join added in v1.2.0

func (ss Strings) Join(glue string) (s string)

Join returns a string from joining each of the elements.

func (Strings) Last

func (ss Strings) Last() string

Last returns the last element, or zero. Also see LastOr().

func (Strings) LastOr

func (ss Strings) LastOr(defaultValue string) string

LastOr returns the last element or a default value if there are no elements.

func (Strings) Len

func (ss Strings) Len() int

Len returns the number of elements.

func (Strings) Map added in v1.14.0

func (ss Strings) Map(fn func(string) string) (ss2 Strings)

Map will return a new slice where each element has been mapped (transformed). The number of elements returned will always be the same as the input.

Be careful when using this with slices of pointers. If you modify the input value it will affect the original slice. Be sure to return a new allocated object or deep copy the existing one.

func (Strings) Max

func (ss Strings) Max() (max string)

Max is the maximum value, or zero.

func (Strings) Min

func (ss Strings) Min() (min string)

Min is the minimum value, or zero.

func (Strings) Random added in v1.12.0

func (ss Strings) Random(source rand.Source) string

Random returns a random element by your rand.Source, or zero

func (Strings) Reduce added in v1.17.0

func (ss Strings) Reduce(reducer func(string, string) string) (el string)

Reduce continually applies the provided function over the slice. Reducing the elements to a single value.

Returns a zero value of string if there are no elements in the slice. It will panic if the reducer is nil and the slice has more than one element (required to invoke reduce). Otherwise returns result of applying reducer from left to right.

func (Strings) Reverse

func (ss Strings) Reverse() Strings

Reverse returns a new copy of the slice with the elements ordered in reverse. This is useful when combined with Sort to get a descending sort order:

ss.Sort().Reverse()

func (Strings) Send added in v1.13.0

func (ss Strings) Send(ctx context.Context, ch chan<- string) Strings

Send sends elements to channel in normal act it sends all elements but if func canceled it can be less

it locks execution of gorutine it doesn't close channel after work returns sended elements if len(this) != len(old) considered func was canceled

func (Strings) Shuffle added in v1.6.0

func (ss Strings) Shuffle(source rand.Source) Strings

Shuffle returns shuffled slice by your rand.Source

func (Strings) Sort

func (ss Strings) Sort() Strings

Sort works similar to sort.Strings(). However, unlike sort.Strings the slice returned will be reallocated as to not modify the input slice.

See Reverse() and AreSorted().

func (Strings) ToStrings added in v1.1.0

func (ss Strings) ToStrings(transform func(string) string) Strings

ToStrings transforms each element to a string.

func (Strings) Top added in v1.7.0

func (ss Strings) Top(n int) (top Strings)

Top will return n elements from head of the slice if the slice has less elements then n that'll return all elements if n < 0 it'll return empty slice.

func (Strings) Unique

func (ss Strings) Unique() Strings

Unique returns a new slice with all of the unique values.

The items will be returned in a randomized order, even with the same input.

The number of items returned may be the same as the input or less. It will never return zero items unless then input slice has zero items.

A slice with zero elements is considered to be unique.

See AreUnique().

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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