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) Diff(against Float64s) (added, removed Float64s)
- func (ss Float64s) DropTop(n int) (drop Float64s)
- func (ss Float64s) Each(fn func(float64)) Float64s
- func (ss Float64s) Extend(slices ...Float64s) (ss2 Float64s)
- func (ss Float64s) Filter(condition func(float64) bool) (ss2 Float64s)
- func (ss Float64s) FilterNot(condition func(float64) bool) (ss2 Float64s)
- func (ss Float64s) FindFirstUsing(fn func(value float64) bool) int
- func (ss Float64s) First() float64
- func (ss Float64s) FirstOr(defaultValue float64) float64
- func (ss Float64s) Float64s() Float64s
- func (ss Float64s) Intersect(slices ...Float64s) (ss2 Float64s)
- func (ss Float64s) Ints() Ints
- func (ss Float64s) JSONBytes() []byte
- func (ss Float64s) JSONBytesIndent(prefix, indent string) []byte
- func (ss Float64s) JSONString() string
- func (ss Float64s) JSONStringIndent(prefix, indent string) string
- func (ss Float64s) Last() float64
- func (ss Float64s) LastOr(defaultValue float64) float64
- func (ss Float64s) Len() int
- func (ss Float64s) Map(fn func(float64) float64) (ss2 Float64s)
- func (ss Float64s) Max() (max float64)
- func (ss Float64s) Median() float64
- func (ss Float64s) Min() (min float64)
- func (ss Float64s) Mode() Float64s
- func (ss Float64s) Product() (product float64)
- func (ss Float64s) Random(source rand.Source) float64
- func (ss Float64s) Reduce(reducer func(float64, float64) float64) (el float64)
- func (ss Float64s) Reverse() Float64s
- func (ss Float64s) Send(ctx context.Context, ch chan<- float64) Float64s
- func (ss Float64s) Sequence(params ...int) Float64s
- func (ss Float64s) SequenceUsing(creator func(int) float64, params ...int) Float64s
- func (ss Float64s) Shuffle(source rand.Source) Float64s
- func (ss Float64s) Sort() Float64s
- func (ss Float64s) Strings() Strings
- func (ss Float64s) SubSlice(start int, end int) (subSlice 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) Unique() 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) Diff(against Ints) (added, removed Ints)
- func (ss Ints) DropTop(n int) (drop Ints)
- func (ss Ints) Each(fn func(int)) Ints
- func (ss Ints) Extend(slices ...Ints) (ss2 Ints)
- func (ss Ints) Filter(condition func(int) bool) (ss2 Ints)
- func (ss Ints) FilterNot(condition func(int) bool) (ss2 Ints)
- func (ss Ints) FindFirstUsing(fn func(value int) bool) int
- func (ss Ints) First() int
- func (ss Ints) FirstOr(defaultValue int) int
- func (ss Ints) Float64s() Float64s
- func (ss Ints) Intersect(slices ...Ints) (ss2 Ints)
- func (ss Ints) Ints() Ints
- func (ss Ints) JSONBytes() []byte
- func (ss Ints) JSONBytesIndent(prefix, indent string) []byte
- func (ss Ints) JSONString() string
- func (ss Ints) JSONStringIndent(prefix, indent string) string
- func (ss Ints) Last() int
- func (ss Ints) LastOr(defaultValue int) int
- func (ss Ints) Len() int
- func (ss Ints) Map(fn func(int) int) (ss2 Ints)
- func (ss Ints) Max() (max int)
- func (ss Ints) Median() int
- func (ss Ints) Min() (min int)
- func (ss Ints) Mode() Ints
- func (ss Ints) Product() (product int)
- func (ss Ints) Random(source rand.Source) int
- func (ss Ints) Reduce(reducer func(int, int) int) (el int)
- func (ss Ints) Reverse() Ints
- func (ss Ints) Send(ctx context.Context, ch chan<- int) Ints
- func (ss Ints) Sequence(params ...int) Ints
- func (ss Ints) SequenceUsing(creator func(int) int, params ...int) Ints
- func (ss Ints) Shuffle(source rand.Source) Ints
- func (ss Ints) Sort() Ints
- func (ss Ints) Strings() Strings
- func (ss Ints) SubSlice(start int, end int) (subSlice 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) Unique() 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) Diff(against Strings) (added, removed Strings)
- func (ss Strings) DropTop(n int) (drop Strings)
- func (ss Strings) Each(fn func(string)) Strings
- func (ss Strings) Extend(slices ...Strings) (ss2 Strings)
- func (ss Strings) Filter(condition func(string) bool) (ss2 Strings)
- func (ss Strings) FilterNot(condition func(string) bool) (ss2 Strings)
- func (ss Strings) FindFirstUsing(fn func(value string) bool) int
- func (ss Strings) First() string
- func (ss Strings) FirstOr(defaultValue string) string
- func (ss Strings) Float64s() Float64s
- func (ss Strings) Intersect(slices ...Strings) (ss2 Strings)
- func (ss Strings) Ints() Ints
- func (ss Strings) JSONBytes() []byte
- func (ss Strings) JSONBytesIndent(prefix, indent string) []byte
- func (ss Strings) JSONString() string
- func (ss Strings) JSONStringIndent(prefix, indent string) 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) Map(fn func(string) string) (ss2 Strings)
- func (ss Strings) Max() (max string)
- func (ss Strings) Min() (min string)
- func (ss Strings) Mode() Strings
- func (ss Strings) Random(source rand.Source) string
- func (ss Strings) Reduce(reducer func(string, string) string) (el string)
- func (ss Strings) Reverse() Strings
- func (ss Strings) Send(ctx context.Context, ch chan<- string) Strings
- func (ss Strings) SequenceUsing(creator func(int) string, params ...int) Strings
- func (ss Strings) Shuffle(source rand.Source) Strings
- func (ss Strings) Sort() Strings
- func (ss Strings) SortStableUsing(less func(a, b string) bool) Strings
- func (ss Strings) SortUsing(less func(a, b string) bool) Strings
- func (ss Strings) Strings() Strings
- func (ss Strings) SubSlice(start int, end int) (subSlice Strings)
- func (ss Strings) ToStrings(transform func(string) string) Strings
- func (ss Strings) Top(n int) (top Strings)
- func (ss Strings) Unique() 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 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) Diff ¶ added in v1.19.0
Diff returns the elements that needs to be added or removed from the first slice to have the same elements in the second slice.
The order of elements is not taken into consideration, so the slices are treated sets that allow duplicate items.
The added and removed returned may be blank respectively, or contain upto as many elements that exists in the largest slice.
func (Float64s) DropTop ¶ added in v1.25.0
DropTop will return the rest slice after dropping the top n elements if the slice has less elements then n that'll return empty slice if n < 0 it'll return empty slice.
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) Filter ¶ added in v1.14.0
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
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) FindFirstUsing ¶ added in v1.27.0
FindFirstUsing will return the index of the first element when the callback returns true or -1 if no element is found. It follows the same logic as the findIndex() function in Javascript.
If the list is empty then -1 is always returned.
func (Float64s) FirstOr ¶
FirstOr returns the first element or a default value if there are no elements.
func (Float64s) Intersect ¶ added in v1.15.0
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) JSONBytes ¶ added in v1.26.0
JSONBytes returns the JSON encoded array as bytes.
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) JSONBytesIndent ¶ added in v1.30.0
JSONBytesIndent returns the JSON encoded array as bytes with indent applied.
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. See json.MarshalIndent for details.
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) JSONStringIndent ¶ added in v1.30.0
JSONStringIndent returns the JSON encoded array as a string with indent applied.
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. See json.MarshalIndent for details.
func (Float64s) LastOr ¶
LastOr returns the last element or a default value if there are no elements.
func (Float64s) Map ¶ added in v1.14.0
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) 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.
If the number of elements is even, then the float64 mean of the two "median values" is returned.
func (Float64s) Mode ¶ added in v1.29.0
Mode returns a new slice containing the most frequently occuring values.
The number of items returned may be the same as the input or less. It will never return zero items unless the input slice has zero items.
func (Float64s) Random ¶ added in v1.12.0
Random returns a random element by your rand.Source, or zero
func (Float64s) Reduce ¶ added in v1.17.0
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 ¶
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
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) Sequence ¶ added in v1.20.0
Sequence generates all numbers in range or returns nil if params invalid
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
func (Float64s) SequenceUsing ¶ added in v1.24.0
SequenceUsing generates slice in range using creator function
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
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) Strings ¶ added in v1.22.0
Strings transforms each element to a string.
If the element type implements fmt.Stringer it will be used. Otherwise it will fallback to the result of:
fmt.Sprintf("%v")
func (Float64s) SubSlice ¶ added in v1.28.0
SubSlice will return the subSlice from start to end(excluded)
Condition 1: If start < 0 or end < 0, nil is returned. Condition 2: If start >= end, nil is returned. Condition 3: Return all elements that exist in the range provided, if start or end is out of bounds, zero items will be placed.
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) 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 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) Diff ¶ added in v1.19.0
Diff returns the elements that needs to be added or removed from the first slice to have the same elements in the second slice.
The order of elements is not taken into consideration, so the slices are treated sets that allow duplicate items.
The added and removed returned may be blank respectively, or contain upto as many elements that exists in the largest slice.
func (Ints) DropTop ¶ added in v1.25.0
DropTop will return the rest slice after dropping the top n elements if the slice has less elements then n that'll return empty slice if n < 0 it'll return empty slice.
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) Filter ¶ added in v1.14.0
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
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) FindFirstUsing ¶ added in v1.27.0
FindFirstUsing will return the index of the first element when the callback returns true or -1 if no element is found. It follows the same logic as the findIndex() function in Javascript.
If the list is empty then -1 is always returned.
func (Ints) FirstOr ¶
FirstOr returns the first element or a default value if there are no elements.
func (Ints) Intersect ¶ added in v1.15.0
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) JSONBytes ¶ added in v1.26.0
JSONBytes returns the JSON encoded array as bytes.
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) JSONBytesIndent ¶ added in v1.30.0
JSONBytesIndent returns the JSON encoded array as bytes with indent applied.
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. See json.MarshalIndent for details.
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) JSONStringIndent ¶ added in v1.30.0
JSONStringIndent returns the JSON encoded array as a string with indent applied.
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. See json.MarshalIndent for details.
func (Ints) Map ¶ added in v1.14.0
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) 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.
If the number of elements is even, then the int mean of the two "median values" is returned.
func (Ints) Mode ¶ added in v1.29.0
Mode returns a new slice containing the most frequently occuring values.
The number of items returned may be the same as the input or less. It will never return zero items unless the input slice has zero items.
func (Ints) Reduce ¶ added in v1.17.0
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 ¶
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
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) Sequence ¶ added in v1.20.0
Sequence generates all numbers in range or returns nil if params invalid
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
func (Ints) SequenceUsing ¶ added in v1.24.0
SequenceUsing generates slice in range using creator function
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
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) Strings ¶ added in v1.22.0
Strings transforms each element to a string.
If the element type implements fmt.Stringer it will be used. Otherwise it will fallback to the result of:
fmt.Sprintf("%v")
func (Ints) SubSlice ¶ added in v1.28.0
SubSlice will return the subSlice from start to end(excluded)
Condition 1: If start < 0 or end < 0, nil is returned. Condition 2: If start >= end, nil is returned. Condition 3: Return all elements that exist in the range provided, if start or end is out of bounds, zero items will be placed.
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) 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 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) Diff ¶ added in v1.19.0
Diff returns the elements that needs to be added or removed from the first slice to have the same elements in the second slice.
The order of elements is not taken into consideration, so the slices are treated sets that allow duplicate items.
The added and removed returned may be blank respectively, or contain upto as many elements that exists in the largest slice.
func (Strings) DropTop ¶ added in v1.25.0
DropTop will return the rest slice after dropping the top n elements if the slice has less elements then n that'll return empty slice if n < 0 it'll return empty slice.
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) Filter ¶ added in v1.14.0
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
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) FindFirstUsing ¶ added in v1.27.0
FindFirstUsing will return the index of the first element when the callback returns true or -1 if no element is found. It follows the same logic as the findIndex() function in Javascript.
If the list is empty then -1 is always returned.
func (Strings) FirstOr ¶
FirstOr returns the first element or a default value if there are no elements.
func (Strings) Intersect ¶ added in v1.15.0
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) JSONBytes ¶ added in v1.26.0
JSONBytes returns the JSON encoded array as bytes.
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) JSONBytesIndent ¶ added in v1.30.0
JSONBytesIndent returns the JSON encoded array as bytes with indent applied.
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. See json.MarshalIndent for details.
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) JSONStringIndent ¶ added in v1.30.0
JSONStringIndent returns the JSON encoded array as a string with indent applied.
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. See json.MarshalIndent for details.
func (Strings) LastOr ¶
LastOr returns the last element or a default value if there are no elements.
func (Strings) Map ¶ added in v1.14.0
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) Mode ¶ added in v1.29.0
Mode returns a new slice containing the most frequently occuring values.
The number of items returned may be the same as the input or less. It will never return zero items unless the input slice has zero items.
func (Strings) Random ¶ added in v1.12.0
Random returns a random element by your rand.Source, or zero
func (Strings) Reduce ¶ added in v1.17.0
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 ¶
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
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) SequenceUsing ¶ added in v1.24.0
SequenceUsing generates slice in range using creator function
There are 3 variations to generate:
- [0, n).
- [min, max).
- [min, max) with step.
if len(params) == 1 considered that will be returned slice between 0 and n, where n is the first param, [0, n). if len(params) == 2 considered that will be returned slice between min and max, where min is the first param, max is the second, [min, max). if len(params) > 2 considered that will be returned slice between min and max with step, where min is the first param, max is the second, step is the third one, [min, max) with step, others params will be ignored
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) SortStableUsing ¶ added in v1.18.0
SortStableUsing works similar to sort.SliceStable. However, unlike sort.SliceStable the slice returned will be reallocated as to not modify the input slice.
func (Strings) SortUsing ¶ added in v1.18.0
SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice.
func (Strings) Strings ¶ added in v1.22.0
Strings transforms each element to a string.
If the element type implements fmt.Stringer it will be used. Otherwise it will fallback to the result of:
fmt.Sprintf("%v")
func (Strings) SubSlice ¶ added in v1.28.0
SubSlice will return the subSlice from start to end(excluded)
Condition 1: If start < 0 or end < 0, nil is returned. Condition 2: If start >= end, nil is returned. Condition 3: Return all elements that exist in the range provided, if start or end is out of bounds, zero items will be placed.
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) 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().