pie

package
v1.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 8 Imported by: 67

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 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) Diff added in v1.19.0

func (ss Float64s) Diff(against Float64s) (added, removed Float64s)

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

func (ss Float64s) DropTop(n int) (drop Float64s)

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

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) Equals added in v1.32.0

func (ss Float64s) Equals(rhs Float64s) bool

Equals compare elements from the start to the end,

if they are the same is considered the slices are equal if all elements are the same is considered the slices are equal if each slice == nil is considered that they're equal

if element realizes Equals interface it uses that method, in other way uses default compare

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) FindFirstUsing added in v1.27.0

func (ss Float64s) FindFirstUsing(fn func(value float64) bool) int

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) 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) Float64s added in v1.23.0

func (ss Float64s) Float64s() Float64s

Float64s transforms each element to a float64.

func (Float64s) Group added in v1.35.0

func (ss Float64s) Group() map[float64]int

Group returns a map of the value with an individual count.

func (Float64s) Insert added in v1.37.0

func (ss Float64s) Insert(index int, values ...float64) Float64s

Insert a value at an index

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) Ints added in v1.23.0

func (ss Float64s) Ints() Ints

Ints transforms each element to an integer.

func (Float64s) JSONBytes added in v1.26.0

func (ss Float64s) JSONBytes() []byte

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

func (ss Float64s) JSONBytesIndent(prefix, indent string) []byte

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

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) JSONStringIndent added in v1.30.0

func (ss Float64s) JSONStringIndent(prefix, indent string) string

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) Join added in v1.34.0

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

Join returns a string from joining each of the elements.

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.

If the number of elements is even, then the float64 mean of the two "median values" is returned.

func (Float64s) Min

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

Min is the minimum value, or zero.

func (Float64s) Mode added in v1.29.0

func (ss Float64s) Mode() Float64s

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) Pop added in v1.36.0

func (ss *Float64s) Pop() (popped *float64)

Pop the first element of the slice

Usage Example:

type knownGreetings []string
greetings := knownGreetings{"ciao", "hello", "hola"}
for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
    fmt.Println(*greeting)
}

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) Sequence added in v1.20.0

func (ss Float64s) Sequence(params ...int) Float64s

Sequence generates all numbers in range or returns nil if params invalid

There are 3 variations to generate:

  1. [0, n).
  2. [min, max).
  3. [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

func (ss Float64s) SequenceUsing(creator func(int) float64, params ...int) Float64s

SequenceUsing generates slice in range using creator function

There are 3 variations to generate:

  1. [0, n).
  2. [min, max).
  3. [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) Shift added in v1.33.0

func (ss Float64s) Shift() (float64, Float64s)

Shift will return two values: the shifted value and the rest slice.

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) Strings added in v1.22.0

func (ss Float64s) Strings() Strings

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) StringsUsing added in v1.31.0

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

StringsUsing transforms each element to a string.

func (Float64s) SubSlice added in v1.28.0

func (ss Float64s) SubSlice(start int, end int) (subSlice Float64s)

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) Sum

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

Sum is the sum of all of the elements.

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().

func (Float64s) Unshift added in v1.33.0

func (ss Float64s) Unshift(elements ...float64) (unshift Float64s)

Unshift adds one or more elements to the beginning of the slice and returns the new slice.

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 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) Diff added in v1.19.0

func (ss Ints) Diff(against Ints) (added, removed Ints)

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

func (ss Ints) DropTop(n int) (drop Ints)

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

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) Equals added in v1.32.0

func (ss Ints) Equals(rhs Ints) bool

Equals compare elements from the start to the end,

if they are the same is considered the slices are equal if all elements are the same is considered the slices are equal if each slice == nil is considered that they're equal

if element realizes Equals interface it uses that method, in other way uses default compare

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) FindFirstUsing added in v1.27.0

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

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) 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) Float64s added in v1.23.0

func (ss Ints) Float64s() Float64s

Float64s transforms each element to a float64.

func (Ints) Group added in v1.35.0

func (ss Ints) Group() map[int]int

Group returns a map of the value with an individual count.

func (Ints) Insert added in v1.37.0

func (ss Ints) Insert(index int, values ...int) Ints

Insert a value at an index

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) Ints added in v1.23.0

func (ss Ints) Ints() Ints

Ints transforms each element to an integer.

func (Ints) JSONBytes added in v1.26.0

func (ss Ints) JSONBytes() []byte

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

func (ss Ints) JSONBytesIndent(prefix, indent string) []byte

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

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) JSONStringIndent added in v1.30.0

func (ss Ints) JSONStringIndent(prefix, indent string) string

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) Join added in v1.34.0

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

Join returns a string from joining each of the elements.

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.

If the number of elements is even, then the int mean of the two "median values" is returned.

func (Ints) Min

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

Min is the minimum value, or zero.

func (Ints) Mode added in v1.29.0

func (ss Ints) Mode() Ints

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) Pop added in v1.36.0

func (ss *Ints) Pop() (popped *int)

Pop the first element of the slice

Usage Example:

type knownGreetings []string
greetings := knownGreetings{"ciao", "hello", "hola"}
for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
    fmt.Println(*greeting)
}

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) Sequence added in v1.20.0

func (ss Ints) Sequence(params ...int) Ints

Sequence generates all numbers in range or returns nil if params invalid

There are 3 variations to generate:

  1. [0, n).
  2. [min, max).
  3. [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

func (ss Ints) SequenceUsing(creator func(int) int, params ...int) Ints

SequenceUsing generates slice in range using creator function

There are 3 variations to generate:

  1. [0, n).
  2. [min, max).
  3. [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) Shift added in v1.33.0

func (ss Ints) Shift() (int, Ints)

Shift will return two values: the shifted value and the rest slice.

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) Strings added in v1.22.0

func (ss Ints) Strings() Strings

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) StringsUsing added in v1.31.0

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

StringsUsing transforms each element to a string.

func (Ints) SubSlice added in v1.28.0

func (ss Ints) SubSlice(start int, end int) (subSlice Ints)

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) Sum

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

Sum is the sum of all of the elements.

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().

func (Ints) Unshift added in v1.33.0

func (ss Ints) Unshift(elements ...int) (unshift Ints)

Unshift adds one or more elements to the beginning of the slice and returns the new slice.

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 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) Diff added in v1.19.0

func (ss Strings) Diff(against Strings) (added, removed Strings)

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

func (ss Strings) DropTop(n int) (drop Strings)

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

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) Equals added in v1.32.0

func (ss Strings) Equals(rhs Strings) bool

Equals compare elements from the start to the end,

if they are the same is considered the slices are equal if all elements are the same is considered the slices are equal if each slice == nil is considered that they're equal

if element realizes Equals interface it uses that method, in other way uses default compare

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) FindFirstUsing added in v1.27.0

func (ss Strings) FindFirstUsing(fn func(value string) bool) int

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) 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) Float64s added in v1.23.0

func (ss Strings) Float64s() Float64s

Float64s transforms each element to a float64.

func (Strings) Group added in v1.35.0

func (ss Strings) Group() map[string]int

Group returns a map of the value with an individual count.

func (Strings) Insert added in v1.37.0

func (ss Strings) Insert(index int, values ...string) Strings

Insert a value at an index

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) Ints added in v1.23.0

func (ss Strings) Ints() Ints

Ints transforms each element to an integer.

func (Strings) JSONBytes added in v1.26.0

func (ss Strings) JSONBytes() []byte

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

func (ss Strings) JSONBytesIndent(prefix, indent string) []byte

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

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) JSONStringIndent added in v1.30.0

func (ss Strings) JSONStringIndent(prefix, indent string) string

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) 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) Mode added in v1.29.0

func (ss Strings) Mode() Strings

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) Pop added in v1.36.0

func (ss *Strings) Pop() (popped *string)

Pop the first element of the slice

Usage Example:

type knownGreetings []string
greetings := knownGreetings{"ciao", "hello", "hola"}
for greeting := greetings.Pop(); greeting != nil; greeting = greetings.Pop() {
    fmt.Println(*greeting)
}

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) SequenceUsing added in v1.24.0

func (ss Strings) SequenceUsing(creator func(int) string, params ...int) Strings

SequenceUsing generates slice in range using creator function

There are 3 variations to generate:

  1. [0, n).
  2. [min, max).
  3. [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) Shift added in v1.33.0

func (ss Strings) Shift() (string, Strings)

Shift will return two values: the shifted value and the rest slice.

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) SortStableUsing added in v1.18.0

func (ss Strings) SortStableUsing(less func(a, b string) bool) Strings

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

func (ss Strings) SortUsing(less func(a, b string) bool) Strings

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

func (ss Strings) Strings() Strings

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) StringsUsing added in v1.31.0

func (ss Strings) StringsUsing(transform func(string) string) Strings

StringsUsing transforms each element to a string.

func (Strings) SubSlice added in v1.28.0

func (ss Strings) SubSlice(start int, end int) (subSlice Strings)

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

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().

func (Strings) Unshift added in v1.33.0

func (ss Strings) Unshift(elements ...string) (unshift Strings)

Unshift adds one or more elements to the beginning of the slice and returns the new slice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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