Documentation ¶
Index ¶
- type Float64s
- func (ss Float64s) Abs() Float64s
- func (ss Float64s) All(fn func(value float64) bool) bool
- func (ss Float64s) Any(fn func(value float64) bool) bool
- func (ss Float64s) Append(elements ...float64) Float64s
- func (ss Float64s) AreSorted() bool
- func (ss Float64s) AreUnique() bool
- func (ss Float64s) Average() float64
- func (ss Float64s) Bottom(n int) (top Float64s)
- func (ss Float64s) Contains(lookingFor float64) bool
- func (ss Float64s) Each(fn func(float64)) Float64s
- func (ss Float64s) Extend(slices ...Float64s) (ss2 Float64s)
- func (ss Float64s) First() float64
- func (ss Float64s) FirstOr(defaultValue float64) float64
- func (ss Float64s) JSONString() string
- func (ss Float64s) Last() float64
- func (ss Float64s) LastOr(defaultValue float64) float64
- func (ss Float64s) Len() int
- func (ss Float64s) Max() (max float64)
- func (ss Float64s) Median() float64
- func (ss Float64s) Min() (min float64)
- func (ss Float64s) Random(source rand.Source) float64
- func (ss Float64s) Reverse() Float64s
- func (ss Float64s) Select(condition func(float64) bool) (ss2 Float64s)
- func (ss Float64s) Shuffle(source rand.Source) Float64s
- func (ss Float64s) Sort() Float64s
- func (ss Float64s) Sum() (sum float64)
- func (ss Float64s) ToStrings(transform func(float64) string) Strings
- func (ss Float64s) Top(n int) (top Float64s)
- func (ss Float64s) Transform(fn func(float64) float64) (ss2 Float64s)
- func (ss Float64s) Unique() Float64s
- func (ss Float64s) Unselect(condition func(float64) bool) (ss2 Float64s)
- type Ints
- func (ss Ints) Abs() Ints
- func (ss Ints) All(fn func(value int) bool) bool
- func (ss Ints) Any(fn func(value int) bool) bool
- func (ss Ints) Append(elements ...int) Ints
- func (ss Ints) AreSorted() bool
- func (ss Ints) AreUnique() bool
- func (ss Ints) Average() float64
- func (ss Ints) Bottom(n int) (top Ints)
- func (ss Ints) Contains(lookingFor int) bool
- func (ss Ints) Each(fn func(int)) Ints
- func (ss Ints) Extend(slices ...Ints) (ss2 Ints)
- func (ss Ints) First() int
- func (ss Ints) FirstOr(defaultValue int) int
- func (ss Ints) JSONString() string
- func (ss Ints) Last() int
- func (ss Ints) LastOr(defaultValue int) int
- func (ss Ints) Len() int
- func (ss Ints) Max() (max int)
- func (ss Ints) Median() int
- func (ss Ints) Min() (min int)
- func (ss Ints) Random(source rand.Source) int
- func (ss Ints) Reverse() Ints
- func (ss Ints) Select(condition func(int) bool) (ss2 Ints)
- func (ss Ints) Shuffle(source rand.Source) Ints
- func (ss Ints) Sort() Ints
- func (ss Ints) Sum() (sum int)
- func (ss Ints) ToStrings(transform func(int) string) Strings
- func (ss Ints) Top(n int) (top Ints)
- func (ss Ints) Transform(fn func(int) int) (ss2 Ints)
- func (ss Ints) Unique() Ints
- func (ss Ints) Unselect(condition func(int) bool) (ss2 Ints)
- type Strings
- func (ss Strings) All(fn func(value string) bool) bool
- func (ss Strings) Any(fn func(value string) bool) bool
- func (ss Strings) Append(elements ...string) Strings
- func (ss Strings) AreSorted() bool
- func (ss Strings) AreUnique() bool
- func (ss Strings) Bottom(n int) (top Strings)
- func (ss Strings) Contains(lookingFor string) bool
- func (ss Strings) Each(fn func(string)) Strings
- func (ss Strings) Extend(slices ...Strings) (ss2 Strings)
- func (ss Strings) First() string
- func (ss Strings) FirstOr(defaultValue string) string
- func (ss Strings) JSONString() string
- func (ss Strings) Join(glue string) (s string)
- func (ss Strings) Last() string
- func (ss Strings) LastOr(defaultValue string) string
- func (ss Strings) Len() int
- func (ss Strings) Max() (max string)
- func (ss Strings) Min() (min string)
- func (ss Strings) Random(source rand.Source) string
- func (ss Strings) Reverse() Strings
- func (ss Strings) Select(condition func(string) bool) (ss2 Strings)
- func (ss Strings) Shuffle(source rand.Source) Strings
- func (ss Strings) Sort() Strings
- func (ss Strings) ToStrings(transform func(string) string) Strings
- func (ss Strings) Top(n int) (top Strings)
- func (ss Strings) Transform(fn func(string) string) (ss2 Strings)
- func (ss Strings) Unique() Strings
- func (ss Strings) Unselect(condition func(string) bool) (ss2 Strings)
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
Abs is a function which returns the absolute value of all the elements in the slice.
func (Float64s) All ¶ added in v1.4.0
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
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
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 ¶
AreSorted will return true if the slice is already sorted. It is a wrapper for sort.Float64sAreSorted.
func (Float64s) AreUnique ¶
AreUnique will return true if the slice contains elements that are all different (unique) from each other.
func (Float64s) Average ¶
Average is the average of all of the elements, or zero if there are no elements.
func (Float64s) Bottom ¶ added in v1.7.0
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 ¶
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
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
Extend will return a new slice with the slices of elements appended to the end.
It is acceptable to provide zero arguments.
func (Float64s) FirstOr ¶
FirstOr returns the first element or a default value if there are no elements.
func (Float64s) JSONString ¶
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) LastOr ¶
LastOr returns the last element or a default value if there are no elements.
func (Float64s) Median ¶ added in v1.9.0
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) Random ¶ added in v1.12.0
Random returns a random element by your rand.Source, or zero
func (Float64s) Reverse ¶
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) Select ¶
Select will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).
Unselect works in the opposite way as Select.
func (Float64s) Sort ¶
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) Top ¶ added in v1.7.0
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) Transform ¶
Transform will return a new slice where each element has been transformed. The number of element 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) Unique ¶
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
Abs is a function which returns the absolute value of all the elements in the slice.
func (Ints) All ¶ added in v1.4.0
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
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
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 ¶
AreSorted will return true if the slice is already sorted. It is a wrapper for sort.IntsAreSorted.
func (Ints) AreUnique ¶
AreUnique will return true if the slice contains elements that are all different (unique) from each other.
func (Ints) Average ¶
Average is the average of all of the elements, or zero if there are no elements.
func (Ints) Bottom ¶ added in v1.7.0
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 ¶
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
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
Extend will return a new slice with the slices of elements appended to the end.
It is acceptable to provide zero arguments.
func (Ints) FirstOr ¶
FirstOr returns the first element or a default value if there are no elements.
func (Ints) JSONString ¶
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) Median ¶ added in v1.9.0
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) Reverse ¶
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) Select ¶
Select will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).
Unselect works in the opposite way as Select.
func (Ints) Sort ¶
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) Top ¶ added in v1.7.0
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) Transform ¶
Transform will return a new slice where each element has been transformed. The number of element 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) Unique ¶
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
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
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
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 ¶
AreSorted will return true if the slice is already sorted. It is a wrapper for sort.StringsAreSorted.
func (Strings) AreUnique ¶
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
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 ¶
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
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
Extend will return a new slice with the slices of elements appended to the end.
It is acceptable to provide zero arguments.
func (Strings) FirstOr ¶
FirstOr returns the first element or a default value if there are no elements.
func (Strings) JSONString ¶
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) LastOr ¶
LastOr returns the last element or a default value if there are no elements.
func (Strings) Random ¶ added in v1.12.0
Random returns a random element by your rand.Source, or zero
func (Strings) Reverse ¶
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) Select ¶
Select will return a new slice containing only the elements that return true from the condition. The returned slice may contain zero elements (nil).
Unselect works in the opposite way as Select.
func (Strings) Sort ¶
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) Top ¶ added in v1.7.0
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) Transform ¶
Transform will return a new slice where each element has been transformed. The number of element 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) Unique ¶
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().