Documentation
¶
Index ¶
- Variables
- func NewCountry() *country
- type CountryInfo
- type CountryList
- func (ss CountryList) All(fn func(value *CountryInfo) bool) bool
- func (ss CountryList) Any(fn func(value *CountryInfo) bool) bool
- func (ss CountryList) Append(elements ...*CountryInfo) CountryList
- func (ss CountryList) Bottom(n int) (top CountryList)
- func (ss CountryList) Contains(lookingFor *CountryInfo) bool
- func (ss CountryList) Diff(against CountryList) (added, removed CountryList)
- func (ss CountryList) DropTop(n int) (drop CountryList)
- func (ss CountryList) Each(fn func(*CountryInfo)) CountryList
- func (ss CountryList) Equals(rhs CountryList) bool
- func (ss CountryList) Extend(slices ...CountryList) (ss2 CountryList)
- func (ss CountryList) Filter(condition func(*CountryInfo) bool) (ss2 CountryList)
- func (ss CountryList) FilterNot(condition func(*CountryInfo) bool) (ss2 CountryList)
- func (ss CountryList) FindFirstUsing(fn func(value *CountryInfo) bool) int
- func (ss CountryList) First() *CountryInfo
- func (ss CountryList) FirstOr(defaultValue *CountryInfo) *CountryInfo
- func (ss CountryList) Float64s() pie.Float64s
- func (ss CountryList) Insert(index int, values ...*CountryInfo) CountryList
- func (ss CountryList) Ints() pie.Ints
- func (ss CountryList) JSONBytes() []byte
- func (ss CountryList) JSONBytesIndent(prefix, indent string) []byte
- func (ss CountryList) JSONString() string
- func (ss CountryList) JSONStringIndent(prefix, indent string) string
- func (ss CountryList) Join(glue string) (s string)
- func (ss CountryList) Last() *CountryInfo
- func (ss CountryList) LastOr(defaultValue *CountryInfo) *CountryInfo
- func (ss CountryList) Len() int
- func (ss CountryList) Map(fn func(*CountryInfo) *CountryInfo) (ss2 CountryList)
- func (ss CountryList) Mode() CountryList
- func (ss *CountryList) Pop() (popped **CountryInfo)
- func (ss CountryList) Random(source rand.Source) *CountryInfo
- func (ss CountryList) Reverse() CountryList
- func (ss CountryList) Send(ctx context.Context, ch chan<- *CountryInfo) CountryList
- func (ss CountryList) SequenceUsing(creator func(int) *CountryInfo, params ...int) CountryList
- func (ss CountryList) Shift() (*CountryInfo, CountryList)
- func (ss CountryList) Shuffle(source rand.Source) CountryList
- func (ss CountryList) SortStableUsing(less func(a, b *CountryInfo) bool) CountryList
- func (ss CountryList) SortUsing(less func(a, b *CountryInfo) bool) CountryList
- func (ss CountryList) Strings() pie.Strings
- func (ss CountryList) StringsUsing(transform func(*CountryInfo) string) pie.Strings
- func (ss CountryList) SubSlice(start int, end int) (subSlice CountryList)
- func (ss CountryList) Top(n int) (top CountryList)
- func (ss CountryList) Unshift(elements ...*CountryInfo) (unshift CountryList)
Constants ¶
This section is empty.
Variables ¶
var Country = NewCountry()
Functions ¶
func NewCountry ¶
func NewCountry() *country
Types ¶
type CountryInfo ¶
type CountryList ¶
type CountryList []*CountryInfo
func (CountryList) All ¶
func (ss CountryList) All(fn func(value *CountryInfo) 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 (CountryList) Any ¶
func (ss CountryList) Any(fn func(value *CountryInfo) 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 (CountryList) Append ¶
func (ss CountryList) Append(elements ...*CountryInfo) CountryList
Append will return a new slice with the elements appended to the end.
It is acceptable to provide zero arguments.
func (CountryList) Bottom ¶
func (ss CountryList) Bottom(n int) (top CountryList)
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 (CountryList) Contains ¶
func (ss CountryList) Contains(lookingFor *CountryInfo) 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 (CountryList) Diff ¶
func (ss CountryList) Diff(against CountryList) (added, removed CountryList)
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 (CountryList) DropTop ¶
func (ss CountryList) DropTop(n int) (drop CountryList)
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 (CountryList) Each ¶
func (ss CountryList) Each(fn func(*CountryInfo)) CountryList
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 (CountryList) Equals ¶
func (ss CountryList) Equals(rhs CountryList) 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 (CountryList) Extend ¶
func (ss CountryList) Extend(slices ...CountryList) (ss2 CountryList)
Extend will return a new slice with the slices of elements appended to the end.
It is acceptable to provide zero arguments.
func (CountryList) Filter ¶
func (ss CountryList) Filter(condition func(*CountryInfo) bool) (ss2 CountryList)
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 (CountryList) FilterNot ¶
func (ss CountryList) FilterNot(condition func(*CountryInfo) bool) (ss2 CountryList)
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 (CountryList) FindFirstUsing ¶
func (ss CountryList) FindFirstUsing(fn func(value *CountryInfo) 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 (CountryList) First ¶
func (ss CountryList) First() *CountryInfo
First returns the first element, or zero. Also see FirstOr().
func (CountryList) FirstOr ¶
func (ss CountryList) FirstOr(defaultValue *CountryInfo) *CountryInfo
FirstOr returns the first element or a default value if there are no elements.
func (CountryList) Float64s ¶
func (ss CountryList) Float64s() pie.Float64s
Float64s transforms each element to a float64.
func (CountryList) Insert ¶
func (ss CountryList) Insert(index int, values ...*CountryInfo) CountryList
Insert a value at an index
func (CountryList) Ints ¶
func (ss CountryList) Ints() pie.Ints
Ints transforms each element to an integer.
func (CountryList) JSONBytes ¶
func (ss CountryList) 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 (CountryList) JSONBytesIndent ¶
func (ss CountryList) 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 (CountryList) JSONString ¶
func (ss CountryList) 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 (CountryList) JSONStringIndent ¶
func (ss CountryList) 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 (CountryList) Join ¶
func (ss CountryList) Join(glue string) (s string)
Join returns a string from joining each of the elements.
func (CountryList) Last ¶
func (ss CountryList) Last() *CountryInfo
Last returns the last element, or zero. Also see LastOr().
func (CountryList) LastOr ¶
func (ss CountryList) LastOr(defaultValue *CountryInfo) *CountryInfo
LastOr returns the last element or a default value if there are no elements.
func (CountryList) Map ¶
func (ss CountryList) Map(fn func(*CountryInfo) *CountryInfo) (ss2 CountryList)
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 (CountryList) Mode ¶
func (ss CountryList) Mode() CountryList
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 (*CountryList) Pop ¶
func (ss *CountryList) Pop() (popped **CountryInfo)
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 (CountryList) Random ¶
func (ss CountryList) Random(source rand.Source) *CountryInfo
Random returns a random element by your rand.Source, or zero
func (CountryList) Reverse ¶
func (ss CountryList) Reverse() CountryList
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 (CountryList) Send ¶
func (ss CountryList) Send(ctx context.Context, ch chan<- *CountryInfo) CountryList
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 (CountryList) SequenceUsing ¶
func (ss CountryList) SequenceUsing(creator func(int) *CountryInfo, params ...int) CountryList
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 (CountryList) Shift ¶
func (ss CountryList) Shift() (*CountryInfo, CountryList)
Shift will return two values: the shifted value and the rest slice.
func (CountryList) Shuffle ¶
func (ss CountryList) Shuffle(source rand.Source) CountryList
Shuffle returns shuffled slice by your rand.Source
func (CountryList) SortStableUsing ¶
func (ss CountryList) SortStableUsing(less func(a, b *CountryInfo) bool) CountryList
SortStableUsing works similar to sort.SliceStable. However, unlike sort.SliceStable the slice returned will be reallocated as to not modify the input slice.
func (CountryList) SortUsing ¶
func (ss CountryList) SortUsing(less func(a, b *CountryInfo) bool) CountryList
SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice.
func (CountryList) Strings ¶
func (ss CountryList) Strings() pie.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 (CountryList) StringsUsing ¶
func (ss CountryList) StringsUsing(transform func(*CountryInfo) string) pie.Strings
StringsUsing transforms each element to a string.
func (CountryList) SubSlice ¶
func (ss CountryList) SubSlice(start int, end int) (subSlice CountryList)
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 (CountryList) Top ¶
func (ss CountryList) Top(n int) (top CountryList)
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 (CountryList) Unshift ¶
func (ss CountryList) Unshift(elements ...*CountryInfo) (unshift CountryList)
Unshift adds one or more elements to the beginning of the slice and returns the new slice.