Documentation ¶
Index ¶
- type Stream
- func (s Stream[T]) All(expression func(item T) bool) bool
- func (s Stream[T]) Append(item T) Stream[T]
- func (s Stream[T]) AppendAt(index int, item T) Stream[T]
- func (s Stream[T]) AppendIf(item T, c bool) Stream[T]
- func (s Stream[T]) ArrEquals(arr []T) bool
- func (s Stream[T]) Average() float64
- func (s Stream[T]) Clear() Stream[T]
- func (s Stream[T]) Collect() []T
- func (s Stream[T]) Contains(item T) bool
- func (s Stream[T]) Count() int
- func (s Stream[T]) Distinct() Stream[T]
- func (s Stream[T]) ElementAt(index int) T
- func (s Stream[T]) ElementAtOrElse(index int, elseValue T) T
- func (s Stream[T]) Equals(b Stream[T]) bool
- func (s Stream[T]) Filter(expression func(item T) bool) Stream[T]
- func (s Stream[T]) Find(expression func(item T) bool) T
- func (s Stream[T]) FindIndex(expression func(item T) bool) int
- func (s Stream[T]) FindLast(expression func(item T) bool) T
- func (s Stream[T]) FindLastIndex(expression func(item T) bool) int
- func (s Stream[T]) First() T
- func (s Stream[T]) ForEach(expression func(item T))
- func (s Stream[T]) IndexOf(item T) int
- func (s Stream[T]) IsEmpty() bool
- func (s Stream[T]) IsNotEmpty() bool
- func (s Stream[T]) Join(separator string) string
- func (s Stream[T]) Last() T
- func (s Stream[T]) LastIndexOf(item T) int
- func (s Stream[T]) Limit(amount int) Stream[T]
- func (s Stream[T]) Map(expression func(item T) T) Stream[T]
- func (s Stream[T]) Max() T
- func (s Stream[T]) MaxIndex() int
- func (s Stream[T]) Min() T
- func (s Stream[T]) MinIndex() int
- func (s Stream[T]) OrderBy() Stream[T]
- func (s Stream[T]) OrderByDescending() Stream[T]
- func (s Stream[T]) Remove(item T) Stream[T]
- func (s Stream[T]) RemoveAt(index int) Stream[T]
- func (s Stream[T]) RemoveDuplicates() Stream[T]
- func (s Stream[T]) RemoveIf(item T, c bool) Stream[T]
- func (s Stream[T]) RemoveWhere(expression func(item T) bool) Stream[T]
- func (s Stream[T]) Reverse() Stream[T]
- func (s Stream[T]) Shuffle() Stream[T]
- func (s Stream[T]) Some(expression func(item T) bool) bool
- func (s Stream[T]) Sum() T
- func (s Stream[T]) Wait(duration time.Duration) Stream[T]
- type Streamable
- type StructStream
- func (s StructStream[T]) All(expression func(item T) bool) bool
- func (s StructStream[T]) Append(item T) StructStream[T]
- func (s StructStream[T]) AppendAt(index int, item T) StructStream[T]
- func (s StructStream[T]) AppendIf(item T, c bool) StructStream[T]
- func (s StructStream[T]) ArrEquals(arr []T) bool
- func (s StructStream[T]) Average(fieldName string) float64
- func (s StructStream[T]) Clear() StructStream[T]
- func (s StructStream[T]) Collect() []T
- func (s StructStream[T]) Contains(item T) bool
- func (s StructStream[T]) Count() int
- func (s StructStream[T]) ElementAt(index int) T
- func (s StructStream[T]) ElementAtOrElse(index int, elseValue T) T
- func (s StructStream[T]) Equals(b StructStream[T]) bool
- func (s StructStream[T]) Filter(expression func(item T) bool) StructStream[T]
- func (s StructStream[T]) Find(expression func(item T) bool) T
- func (s StructStream[T]) FindIndex(expression func(item T) bool) int
- func (s StructStream[T]) FindLast(expression func(item T) bool) T
- func (s StructStream[T]) FindLastIndex(expression func(item T) bool) int
- func (s StructStream[T]) First() T
- func (s StructStream[T]) ForEach(expression func(item T))
- func (s StructStream[T]) IndexOf(item T) int
- func (s StructStream[T]) IsEmpty() bool
- func (s StructStream[T]) IsNotEmpty() bool
- func (s StructStream[T]) Last() T
- func (s StructStream[T]) LastIndexOf(item T) int
- func (s StructStream[T]) Limit(amount int) StructStream[T]
- func (s StructStream[T]) Map(expression func(item T) T) StructStream[T]
- func (s StructStream[T]) Max(fieldName string) T
- func (s StructStream[T]) MaxIndex(fieldName string) int
- func (s StructStream[T]) Min(fieldName string) T
- func (s StructStream[T]) MinIndex(fieldName string) int
- func (s StructStream[T]) OrderBy(fieldName string) StructStream[T]
- func (s StructStream[T]) OrderByDescending(fieldName string) StructStream[T]
- func (s StructStream[T]) Remove(item T) StructStream[T]
- func (s StructStream[T]) RemoveAt(index int) StructStream[T]
- func (s StructStream[T]) RemoveIf(item T, c bool) StructStream[T]
- func (s StructStream[T]) RemoveWhere(expression func(item T) bool) StructStream[T]
- func (s StructStream[T]) Reverse() StructStream[T]
- func (s StructStream[T]) Shuffle() StructStream[T]
- func (s StructStream[T]) Some(expression func(item T) bool) bool
- func (s StructStream[T]) Sum(fieldName string) float64
- func (s StructStream[T]) Wait(duration time.Duration) StructStream[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stream ¶
type Stream[T Streamable] struct { Array []T }
func Empty ¶ added in v1.1.0
func Empty[T Streamable]() Stream[T]
The Empty function returns an empty stream.
func FromArray ¶
func FromArray[T Streamable](array []T) Stream[T]
The FromArray function creates a new stream from the given array.
func FromFile ¶ added in v1.2.0
The FromFile function creates a stream from a file. The file is read line by line. Each line is an element of the stream.
func FromValues ¶ added in v1.1.0
func FromValues[T Streamable](values ...T) Stream[T]
The FromValues function returns a stream made of the specified parameters.
func (Stream[T]) All ¶ added in v1.1.0
The All function determines whether all elements of the stream satisfy the passed condition.
func (Stream[T]) AppendAt ¶
The AppendAt function inserts the specified element at the specified position in the stream.
func (Stream[T]) AppendIf ¶ added in v1.1.0
The AppendIf function adds an element to the stream if the second parameter is true.
func (Stream[T]) ArrEquals ¶ added in v1.1.0
The ArrEquals function compares the stream and the passed array and returns true if they're equals.
func (Stream[T]) Average ¶ added in v1.1.0
The Average function calculates the average of the stream. This function doesn't work with strings.
func (Stream[T]) Collect ¶
func (s Stream[T]) Collect() []T
The Collect function returns the modified array from the streams.
func (Stream[T]) Contains ¶
The Contains function checks whether the stream contains the passed item.
func (Stream[T]) Distinct ¶ added in v1.1.0
The Distinct function filters every distinct element from the stream.
func (Stream[T]) ElementAt ¶ added in v1.1.0
The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it throws a panic.
func (Stream[T]) ElementAtOrElse ¶ added in v1.1.0
The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it returns the elseValue, which is the second parameter.
func (Stream[T]) Equals ¶ added in v1.1.0
The Equals function compares two streams and returns true if they're equals.
func (Stream[T]) Filter ¶
The Filter function leaves only those elements in the array that make the specified condition true.
func (Stream[T]) Find ¶ added in v1.1.0
The Find function searches for an element that matches the conditions passed and returns the first occurrence within the entire stream.
func (Stream[T]) FindIndex ¶ added in v1.1.0
The FindIndex function searches for an element that matches the conditions passed and returns the index of the first occurrence within the entire stream.
func (Stream[T]) FindLast ¶ added in v1.1.0
The FindLast function searches for an element that matches the conditions passed and returns the last occurrence within the entire stream.
func (Stream[T]) FindLastIndex ¶ added in v1.1.0
The FindLastIndex function searches for an element that matches the conditions passed and returns the index of the last occurrence within the entire stream.
func (Stream[T]) First ¶ added in v1.2.1
func (s Stream[T]) First() T
The First method returns the first element in the stream.
func (Stream[T]) ForEach ¶
func (s Stream[T]) ForEach(expression func(item T))
The ForEach method runs the specified method with every element in the Stream.
func (Stream[T]) IndexOf ¶ added in v1.1.0
The IndexOf function returns the position of the first occurrence of the passed value in a stream.
func (Stream[T]) IsNotEmpty ¶ added in v1.2.1
The IsNotEmpty function checks whether the stream is not empty.
func (Stream[T]) Join ¶
Join concatenates the elements of the stream to create a single string. The passed parameter is placed between the elements.
func (Stream[T]) Last ¶ added in v1.2.1
func (s Stream[T]) Last() T
The Last method returns the last element in the stream.
func (Stream[T]) LastIndexOf ¶ added in v1.1.0
The LastIndexOf function returns the position of the last occurrence of the passed value in a stream.
func (Stream[T]) Limit ¶
The Limit function constrains the number of elements returned by the stream.
func (Stream[T]) Map ¶
The Map function creates a new stream populated with the results of calling the provided function on every element.
func (Stream[T]) Max ¶ added in v1.1.0
func (s Stream[T]) Max() T
The Max function returns the largest element from the stream.
func (Stream[T]) MaxIndex ¶ added in v1.1.0
The MaxIndex function returns the index of the largest element from the stream.
func (Stream[T]) Min ¶ added in v1.1.0
func (s Stream[T]) Min() T
The Min function returns the smallest element from the stream.
func (Stream[T]) MinIndex ¶ added in v1.1.0
The MaxIndex function returns the index of the smallest element from the stream.
func (Stream[T]) OrderByDescending ¶
The OrderByDescending function sorts the stream in descending order.
func (Stream[T]) RemoveAt ¶
The RemoveAt function removes the item if its index matches the index passed in.
func (Stream[T]) RemoveDuplicates ¶
The RemoveDuplicates function removes every duplicate item from the stream.
func (Stream[T]) RemoveIf ¶ added in v1.1.0
The RemoveIf function removes the passed element from a stream if the second parameter is true.
func (Stream[T]) RemoveWhere ¶
The RemoveWhere function removes all the entries that satisfy the provided condition.
func (Stream[T]) Some ¶ added in v1.1.0
The Some function determines whether any of the elements of the stream satisfy the passed condition.
type Streamable ¶
type Streamable interface { string | byte | float32 | float64 | int | int16 | int32 | int64 | uint16 | uint32 | uint64 }
The Streamable interface defines every type you can use the streams with.
type StructStream ¶ added in v1.2.0
type StructStream[T interface{}] struct {
Array []T
}
func FromStructs ¶ added in v1.2.0
func FromStructs[T interface{}](array []T) StructStream[T]
The FromStruct function creates a new stream from the given struct array. If the given array is not made of struct, it throws an error.
func (StructStream[T]) All ¶ added in v1.2.0
func (s StructStream[T]) All(expression func(item T) bool) bool
The All function determines whether all elements of the stream satisfy the passed condition.
func (StructStream[T]) Append ¶ added in v1.2.0
func (s StructStream[T]) Append(item T) StructStream[T]
The Append function adds an element to the stream.
func (StructStream[T]) AppendAt ¶ added in v1.2.0
func (s StructStream[T]) AppendAt(index int, item T) StructStream[T]
The AppendAt function inserts the specified element at the specified position in the stream.
func (StructStream[T]) AppendIf ¶ added in v1.2.0
func (s StructStream[T]) AppendIf(item T, c bool) StructStream[T]
The AppendIf function adds an element to the stream if the second parameter is true.
func (StructStream[T]) ArrEquals ¶ added in v1.2.0
func (s StructStream[T]) ArrEquals(arr []T) bool
The ArrEquals function compares the stream and the passed array and returns true if they're equals.
func (StructStream[T]) Average ¶ added in v1.2.0
func (s StructStream[T]) Average(fieldName string) float64
The Average function calculates the average of the stream. This function doesn't work with strings. The first parameter is the name of the field you want to calculate by.
func (StructStream[T]) Clear ¶ added in v1.2.0
func (s StructStream[T]) Clear() StructStream[T]
The Clear function clears every element from the stream.
func (StructStream[T]) Collect ¶ added in v1.2.0
func (s StructStream[T]) Collect() []T
The Collect function returns the modified array from the streams.
func (StructStream[T]) Contains ¶ added in v1.2.0
func (s StructStream[T]) Contains(item T) bool
The Contains function checks whether the stream contains the passed item.
func (StructStream[T]) Count ¶ added in v1.2.0
func (s StructStream[T]) Count() int
The Count function returns the count of elements in the stream.
func (StructStream[T]) ElementAt ¶ added in v1.2.0
func (s StructStream[T]) ElementAt(index int) T
The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it throws a panic.
func (StructStream[T]) ElementAtOrElse ¶ added in v1.2.0
func (s StructStream[T]) ElementAtOrElse(index int, elseValue T) T
The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it returns the elseValue, which is the second parameter.
func (StructStream[T]) Equals ¶ added in v1.2.0
func (s StructStream[T]) Equals(b StructStream[T]) bool
The Equals function compares two streams and returns true if they're equals.
func (StructStream[T]) Filter ¶ added in v1.2.0
func (s StructStream[T]) Filter(expression func(item T) bool) StructStream[T]
The Filter function leaves only those elements in the array that make the specified condition true.
func (StructStream[T]) Find ¶ added in v1.2.0
func (s StructStream[T]) Find(expression func(item T) bool) T
The Find function searches for an element that matches the conditions passed and returns the first occurrence within the entire stream.
func (StructStream[T]) FindIndex ¶ added in v1.2.0
func (s StructStream[T]) FindIndex(expression func(item T) bool) int
The FindIndex function searches for an element that matches the conditions passed and returns the index of the first occurrence within the entire stream.
func (StructStream[T]) FindLast ¶ added in v1.2.0
func (s StructStream[T]) FindLast(expression func(item T) bool) T
The FindLast function searches for an element that matches the conditions passed and returns the last occurrence within the entire stream.
func (StructStream[T]) FindLastIndex ¶ added in v1.2.0
func (s StructStream[T]) FindLastIndex(expression func(item T) bool) int
The FindLastIndex function searches for an element that matches the conditions passed and returns the index of the last occurrence within the entire stream.
func (StructStream[T]) First ¶ added in v1.2.1
func (s StructStream[T]) First() T
The First method returns the first element in the stream.
func (StructStream[T]) ForEach ¶ added in v1.2.0
func (s StructStream[T]) ForEach(expression func(item T))
The ForEach method runs the specified method with every element in the Stream.
func (StructStream[T]) IndexOf ¶ added in v1.2.0
func (s StructStream[T]) IndexOf(item T) int
The IndexOf function returns the position of the first occurrence of the passed value in a stream.
func (StructStream[T]) IsEmpty ¶ added in v1.2.0
func (s StructStream[T]) IsEmpty() bool
The IsEmpty function checks whether the stream is empty.
func (StructStream[T]) IsNotEmpty ¶ added in v1.2.1
func (s StructStream[T]) IsNotEmpty() bool
The IsNotEmpty function checks whether the stream is not empty.
func (StructStream[T]) Last ¶ added in v1.2.1
func (s StructStream[T]) Last() T
The Last method returns the last element in the stream.
func (StructStream[T]) LastIndexOf ¶ added in v1.2.0
func (s StructStream[T]) LastIndexOf(item T) int
The LastIndexOf function returns the position of the last occurrence of the passed value in a stream.
func (StructStream[T]) Limit ¶ added in v1.2.0
func (s StructStream[T]) Limit(amount int) StructStream[T]
The Limit function constrains the number of elements returned by the stream.
func (StructStream[T]) Map ¶ added in v1.2.0
func (s StructStream[T]) Map(expression func(item T) T) StructStream[T]
The Map function creates a new stream populated with the results of calling the provided function on every element.
func (StructStream[T]) Max ¶ added in v1.2.0
func (s StructStream[T]) Max(fieldName string) T
The Max function returns the largest element from the stream. The first parameter is the name of the field you want to calculate by.
func (StructStream[T]) MaxIndex ¶ added in v1.2.0
func (s StructStream[T]) MaxIndex(fieldName string) int
The MaxIndex function returns the index of the largest element from the stream. The first parameter is the name of the field you want to calculate by.
func (StructStream[T]) Min ¶ added in v1.2.0
func (s StructStream[T]) Min(fieldName string) T
The Min function returns the smallest element from the stream. The first parameter is the name of the field you want to calculate by.
func (StructStream[T]) MinIndex ¶ added in v1.2.0
func (s StructStream[T]) MinIndex(fieldName string) int
The MaxIndex function returns the index of the smallest element from the stream. The first parameter is the name of the field you want to calculate by.
func (StructStream[T]) OrderBy ¶ added in v1.2.0
func (s StructStream[T]) OrderBy(fieldName string) StructStream[T]
The OrderBy function sorts the stream in ascending order. The first parameter is the name of the field you want to sort by.
func (StructStream[T]) OrderByDescending ¶ added in v1.2.0
func (s StructStream[T]) OrderByDescending(fieldName string) StructStream[T]
The OrderByDescending function sorts the stream in descending order The first parameter is the name of the field you want to sort by.
func (StructStream[T]) Remove ¶ added in v1.2.0
func (s StructStream[T]) Remove(item T) StructStream[T]
The Remove function removes the passed element from a stream.
func (StructStream[T]) RemoveAt ¶ added in v1.2.0
func (s StructStream[T]) RemoveAt(index int) StructStream[T]
The RemoveAt function removes the item if its index matches the index passed in.
func (StructStream[T]) RemoveIf ¶ added in v1.2.0
func (s StructStream[T]) RemoveIf(item T, c bool) StructStream[T]
The RemoveIf function removes the passed element from a stream if the second parameter is true.
func (StructStream[T]) RemoveWhere ¶ added in v1.2.0
func (s StructStream[T]) RemoveWhere(expression func(item T) bool) StructStream[T]
The RemoveWhere function removes all the entries that satisfy the provided condition.
func (StructStream[T]) Reverse ¶ added in v1.2.0
func (s StructStream[T]) Reverse() StructStream[T]
The Reverse function reverses the stream.
func (StructStream[T]) Shuffle ¶ added in v1.2.1
func (s StructStream[T]) Shuffle() StructStream[T]
The Shuffle function shuffles the stream.
func (StructStream[T]) Some ¶ added in v1.2.0
func (s StructStream[T]) Some(expression func(item T) bool) bool
The Some function determines whether any of the elements of the stream satisfy the passed condition.
func (StructStream[T]) Sum ¶ added in v1.2.0
func (s StructStream[T]) Sum(fieldName string) float64
The Sum function adds up all values in a stream. The first parameter is the name of the field you want to calculate by.
func (StructStream[T]) Wait ¶ added in v1.2.0
func (s StructStream[T]) Wait(duration time.Duration) StructStream[T]
The Wait function pauses the current stream for the duration passed. The first and only parameter expects a value from the built-in time.Duration package.