Documentation
¶
Index ¶
- func FindPosition[T Number](p T) func(T) bool
- func Max[T Ordered](a, b T) bool
- func Min[T Ordered](a, b T) bool
- func OrderAsc[T Ordered](a, b T) bool
- func OrderDesc[T Ordered](a, b T) bool
- func OrderStructAsc[T OrderedStruct[T]](a, b T) bool
- func OrderStructDesc[T OrderedStruct[T]](a, b T) bool
- func Println[T any](v T)
- func Println2[K comparable, T any](k K, v T)
- func Sum[T Number](a, b T) T
- type List
- func (list List[T]) AllMatch(predicate func(T) bool) bool
- func (list List[T]) AnyMatch(predicate func(T) bool) bool
- func (list List[T]) Collect() []T
- func (list List[T]) Count() int
- func (list List[T]) DropWhile(predicate func(T) bool) Steam[T]
- func (list List[T]) Filter(predicate func(T) bool) Steam[T]
- func (list List[T]) FilterMapToAny(predicate func(T) bool, mapper func(T) any) Steam[any]
- func (list List[T]) FindFirst() opt.Optional[T]
- func (list List[T]) FlatMapToAny(mapper func(T) Steam[any]) Steam[any]
- func (list List[T]) FlatMapToInt(mapper func(T) Steam[int]) Steam[int]
- func (list List[T]) FlatMapToString(mapper func(T) Steam[string]) Steam[string]
- func (list List[T]) ForEach(consumer func(T))
- func (list List[T]) GetCompared(cmp func(T, T) bool) opt.Optional[T]
- func (list List[T]) Last() opt.Optional[T]
- func (list List[T]) Limit(limit int) Steam[T]
- func (list List[T]) MapToAny(mapper func(T) any) Steam[any]
- func (list List[T]) MapToInt(mapper func(T) int) Steam[int]
- func (list List[T]) MapToString(mapper func(T) string) Steam[string]
- func (list List[T]) NoneMatch(predicate func(T) bool) bool
- func (list List[T]) Peek(consumer func(T)) Steam[T]
- func (list List[T]) Position(predicate func(T) bool) opt.Optional[int]
- func (list List[T]) Reduce(initValue T, acc func(T, T) T) T
- func (list List[T]) Reverse() Steam[T]
- func (list List[T]) Skip(n int) Steam[T]
- func (list List[T]) Sorted(cmp func(T, T) bool) Steam[T]
- func (list List[T]) TakeWhile(predicate func(T) bool) Steam[T]
- type Map
- func (m Map[K, V]) AllMatch(predicate func(K, V) bool) bool
- func (m Map[K, V]) AnyMatch(predicate func(K, V) bool) bool
- func (m Map[K, V]) Collect() map[K]V
- func (m Map[K, V]) Count() int
- func (m Map[K, V]) Filter(predicate func(K, V) bool) Steam2[K, V]
- func (m Map[K, V]) FilterMapToAny(predicate func(K, V) bool, mapper func(K, V) any) Steam2[K, any]
- func (m Map[K, V]) ForEach(consumer func(K, V))
- func (m Map[K, V]) GetCompared(cmp func(K, K) bool) opt.Optional[Pair[K, V]]
- func (m Map[K, V]) KeysToSteam() Steam[K]
- func (m Map[K, V]) Limit(limit int) Steam2[K, V]
- func (m Map[K, V]) MapToAny(mapper func(K, V) any) Steam2[K, any]
- func (m Map[K, V]) MapToInt(mapper func(K, V) int) Steam2[K, int]
- func (m Map[K, V]) MapToString(mapper func(K, V) string) Steam2[K, string]
- func (m Map[K, V]) NoneMatch(predicate func(K, V) bool) bool
- func (m Map[K, V]) Peek(consumer func(K, V)) Steam2[K, V]
- func (m Map[K, V]) Sorted(cmp func(K, K) bool) Steam2[K, V]
- func (m Map[K, V]) ToAnySteam(mapper func(K, V) any) Steam[any]
- func (m Map[K, V]) ValuesToSteam() Steam[V]
- type Number
- type Ordered
- type OrderedStruct
- type Pair
- type Steam
- func CollectSteam2ToSteam[K comparable, V, R any](s Steam2[K, V], mapper func(K, V) R) Steam[R]
- func Distinct[T comparable](s Steam[T]) Steam[T]
- func ListOf[T any](args ...T) Steam[T]
- func Mapping[T, R any](s Steam[T], mapper func(T) R) Steam[R]
- func Of[T any](args ...T) Steam[T]
- func OfSlice[T any](slice []T) Steam[T]
- func Zip[T, R any](s1 Steam[T], s2 Steam[R]) ...
- type Steam2
- func CollectSteamToSteam2[K comparable, V, T any](s Steam[T], keyFunc func(T) K, valueFunc func(T) V) Steam2[K, V]
- func GroupBy[K comparable, V any](s Steam[V], classifier func(V) K) Steam2[K, Steam[V]]
- func GroupByCounting[K comparable, V any](s Steam[V], classifier func(V) K) Steam2[K, int]
- func OfMap[K comparable, V any](m map[K]V) Steam2[K, V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindPosition ¶
FindPosition returns a function that checks if a given value x is equal to the specified position p. The returned function takes a single argument of type T and returns true if it matches p.
func Max ¶
Max returns true if the first argument a is less than the second argument b. It is intended to be used with types that implement the Ordered interface, which allows for comparison operations.
func Min ¶
Min returns true if the first argument a is greater than the second argument b. It is intended to be used with types that implement the Ordered interface, which allows for comparison operations.
func OrderAsc ¶
OrderAsc compares two Ordered values in ascending order. It returns true if the first value is greater than the second.
func OrderDesc ¶
OrderDesc compares two Ordered values in descending order. It returns true if the first value is less than the second.
func OrderStructAsc ¶
func OrderStructAsc[T OrderedStruct[T]](a, b T) bool
OrderStructAsc compares two OrderedStructs in ascending order. It returns true if the first struct is greater than the second.
func OrderStructDesc ¶
func OrderStructDesc[T OrderedStruct[T]](a, b T) bool
OrderStructDesc compares two OrderedStructs in descending order. It returns true if the first struct is less than the second.
func Println ¶
func Println[T any](v T)
Println prints the value of the provided argument v to the standard output. It can accept any type of value due to the use of a type parameter T.
func Println2 ¶
func Println2[K comparable, T any](k K, v T)
Println prints the values of the provided arguments k and v to the standard output. It can accept a comparable K value and any type to second value due to the use of a type parameter T.
Types ¶
type List ¶
type List[T any] []T
List is a generic type that represents a slice of elements of type T. It provides methods to perform various operations on the list, following a functional programming style.
func (List[T]) AllMatch ¶
AllMatch checks if all elements in the List match the provided predicate function. It returns true if all elements match, false otherwise.
func (List[T]) AnyMatch ¶
AnyMatch checks if any element in the List matches the provided predicate function. It returns true if at least one element matches, false otherwise.
func (List[T]) Collect ¶
func (list List[T]) Collect() []T
Collect returns the underlying slice of the List.
func (List[T]) DropWhile ¶
DropWhile returns a new List that skips elements from the start of the List as long as they match the provided predicate function. It includes all subsequent elements after the first non-matching element.
func (List[T]) Filter ¶
Filter returns a new List containing only the elements that match the provided predicate function.
func (List[T]) FilterMapToAny ¶
FilterMapToAny filters the elements based on the provided predicate and then maps the remaining elements using the provided mapper function, returning a new List of type any.
func (List[T]) FindFirst ¶
FindFirst returns an Optional containing the first element of the List if it is present; otherwise, it returns an empty Optional.
func (List[T]) FlatMapToAny ¶
FlatMapToAny applies the provided mapper function to each element in the List, which returns a Steam, and concatenates the results into a single List of type any.
func (List[T]) FlatMapToInt ¶ added in v0.2.0
FlatMapToInt applies the provided mapper function to each element in the List, which returns a Steam, and concatenates the results into a single List of type int.
func (List[T]) FlatMapToString ¶ added in v0.2.0
FlatMapToString applies the provided mapper function to each element in the List, which returns a Steam, and concatenates the results into a single List of type string.
func (List[T]) ForEach ¶
func (list List[T]) ForEach(consumer func(T))
ForEach applies the provided consumer function to each element in the List.
func (List[T]) GetCompared ¶
GetCompared returns an Optional containing the element that is compared according to the provided comparison function. If the List is empty, it returns an empty Optional.
func (List[T]) Last ¶
Last returns an Optional containing the last element of the List if it is present; otherwise, it returns an empty Optional.
func (List[T]) Limit ¶
Limit restricts the number of elements in the List to the specified limit and returns a new List.
func (List[T]) MapToAny ¶
MapToAny applies the provided mapper function to each element in the List and returns a new List of type any. If result to specific type is needed, use integration function Mapping[T, R](s Steam[T], mapper func(T) R)
func (List[T]) MapToInt ¶
MapToInt applies the provided mapper function to each element in the List and returns a new List of integers.
func (List[T]) MapToString ¶
MapToString applies the provided mapper function to each element in the List and returns a new List of strings.
func (List[T]) NoneMatch ¶
NoneMatch checks if no elements in the List match the provided predicate function. It returns true if no elements match, false otherwise.
func (List[T]) Peek ¶
Peek applies the provided consumer function to each element in the List without modifying it, and returns the original List.
func (List[T]) Position ¶
Position returns an Optional containing the index of the first element that matches the provided predicate function; otherwise, it returns an empty Optional.
func (List[T]) Reduce ¶
func (list List[T]) Reduce(initValue T, acc func(T, T) T) T
Reduce applies an accumulator function to the elements of the List, starting with the provided initial value. It returns the final accumulated value.
func (List[T]) Reverse ¶
Reverse returns a new List containing the elements of the original List in reverse order.
func (List[T]) Skip ¶
Skip returns a new List that skips the first n elements of the original List. If n is greater than or equal to the length of the List, it returns an empty List.
type Map ¶
type Map[K comparable, V any] map[K]V
Map is a generic type that represents a collection of key-value pairs, where keys are of type K and values are of type V.
func (Map[K, V]) AllMatch ¶
AllMatch checks if all key-value pairs in the Map match the provided predicate function. It returns true if all pairs match; otherwise, it returns false.
func (Map[K, V]) AnyMatch ¶
AnyMatch checks if any key-value pair in the Map matches the provided predicate function. It returns true if at least one pair matches; otherwise, it returns false.
func (Map[K, V]) Collect ¶
func (m Map[K, V]) Collect() map[K]V
Collect returns the underlying map of key-value pairs.
func (Map[K, V]) Filter ¶
Filter returns a new Map containing only the key-value pairs that match the provided predicate function.
func (Map[K, V]) FilterMapToAny ¶
FilterMapToAny filters the key-value pairs based on the provided predicate and then maps the remaining pairs using the provided mapper function, returning a new Map with values of type any.
func (Map[K, V]) ForEach ¶
func (m Map[K, V]) ForEach(consumer func(K, V))
ForEach applies the provided consumer function to each key-value pair in the Map.
func (Map[K, V]) GetCompared ¶
GetCompared returns an Optional containing the key-value pair that is compared according to the provided comparison function. If the Map is empty, it returns an empty Optional.
func (Map[K, V]) KeysToSteam ¶
KeysToSteam returns a Steam containing all the keys from the Map.
func (Map[K, V]) Limit ¶
Limit restricts the number of key-value pairs in the Map to the specified limit and returns a new Map containing only the first 'limit' pairs.
func (Map[K, V]) MapToAny ¶
MapToAny applies the provided mapper function to each key-value pair in the Map and returns a new Map with values of type any.
func (Map[K, V]) MapToInt ¶
MapToInt applies the provided mapper function to each key-value pair in the Map and returns a new Map with values of type int.
func (Map[K, V]) MapToString ¶
MapToString applies the provided mapper function to each key-value pair in the Map and returns a new Map with values of type string.
func (Map[K, V]) NoneMatch ¶
NoneMatch checks if no key-value pairs in the Map match the provided predicate function. It returns true if no pairs match; otherwise, it returns false.
func (Map[K, V]) Peek ¶
Peek applies the provided consumer function to each key-value pair in the Map without modifying it, and returns the original Map.
func (Map[K, V]) Sorted ¶
Sorted returns a new Map containing the key-value pairs sorted according to the provided comparison function. The comparison function should define the order of the keys.
func (Map[K, V]) ToAnySteam ¶
ToAnySteam applies the provided mapper function to each key-value pair in the Map and returns a Steam containing the mapped values of type any.
func (Map[K, V]) ValuesToSteam ¶
ValuesToSteam returns a Steam containing all the values from the Map.
type Number ¶
type Number interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
}
Number is a type constraint that includes all sumable types. It allows for summing various numeric types.
type Ordered ¶
Ordered is a type constraint that includes all ordered types. It allows for comparison of various numeric types and strings.
type OrderedStruct ¶
OrderedStruct is an interface for structs that can be compared. It requires the implementation of a Compare method that returns an integer. The method should return a negative value if the receiver is less than the other, zero if they are equal, and a positive value if the receiver is greater.
type Pair ¶
type Pair[K comparable, V any] struct { Key K Value V }
Pair is a generic struct that holds a key-value pair.
type Steam ¶
type Steam[T any] interface { // Filter returns a new Steam containing only the elements that match the // given predicate function. Filter(predicate func(T) bool) Steam[T] // MapToAny transforms each element of the Steam using the provided mapper // function and returns a new Steam of type any. // If result to specific type is needed, use integration function Mapping[T, R](s Steam[T], mapper func(T) R) MapToAny(mapper func(T) any) Steam[any] // MapToInt transforms each element of the Steam using the provided mapper // function and returns a new Steam of type int. MapToInt(mapper func(T) int) Steam[int] // MapToString transforms each element of the Steam using the provided mapper // function and returns a new Steam of type string. MapToString(mapper func(T) string) Steam[string] // FilterMapToAny combines filtering and mapping. Returns a new Steam containing // elements that match the predicate and are transformed by the mapper. FilterMapToAny(predicate func(T) bool, mapper func(T) any) Steam[any] // FlatMapToAny transforms each element of the Steam into a new Steam using // the provided mapper function and flattens the result into a single Steam. FlatMapToAny(mapper func(T) Steam[any]) Steam[any] // FlatMapToInt transforms each element of the Steam into a new Steam using // the provided mapper function and flattens the result into a single Steam. FlatMapToInt(mapper func(T) Steam[int]) Steam[int] // FlatMapToString transforms each element of the Steam into a new Steam using // the provided mapper function and flattens the result into a single Steam. FlatMapToString(mapper func(T) Steam[string]) Steam[string] // ForEach executes the provided consumer function for each element in the Steam. ForEach(consumer func(T)) // Peek allows for inspecting each element without consuming it. It returns // a new Steam that allows for further operations after consuming the elements. Peek(consumer func(T)) Steam[T] // Limit returns a new Steam containing only the first 'limit' elements. Limit(limit int) Steam[T] // AllMatch returns true if all elements match the given predicate. AllMatch(predicate func(T) bool) bool // AnyMatch returns true if any element matches the given predicate. AnyMatch(predicate func(T) bool) bool // NoneMatch returns true if no elements match the given predicate. NoneMatch(predicate func(T) bool) bool // TakeWhile returns a new Steam containing elements as long as they match // the given predicate. TakeWhile(predicate func(T) bool) Steam[T] // DropWhile returns a new Steam that skips elements as long as they match // the given predicate. DropWhile(predicate func(T) bool) Steam[T] // Reduce combines elements of the Steam into a single value using the provided // accumulator function, starting with the given initial value. Reduce(initValue T, acc func(T, T) T) T // Reverse returns a new Steam with the elements in reverse order. Reverse() Steam[T] // Sorted returns a new Steam with the elements sorted according to the // provided comparison function. Sorted(cmp func(T, T) bool) Steam[T] // GetCompared returns the first element that matches the comparison function // wrapped in an opt.Optional[T]. // This can be used as an implementation of Max or Min function. GetCompared(cmp func(T, T) bool) opt.Optional[T] // FindFirst returns the first element in the Steam as an opt.Optional[T] // indicating if an element exists. FindFirst() opt.Optional[T] // Last returns an opt.Optional of the last element in the Steam // indicating if an element exists. Last() opt.Optional[T] // Position returns the index of the first element that matches the predicate // wrapped in an opt.Optional[int]. Position(predicate func(T) bool) opt.Optional[int] // Skip returns a new Steam that skips the first 'n' elements. Skip(n int) Steam[T] // Count returns the number of elements in the Steam. Count() int // Collect returns a slice containing all elements in the Steam. Collect() []T }
Steam[T] is an interface for a collection of elements of type T, providing various methods for functional-style processing.
func CollectSteam2ToSteam ¶
func CollectSteam2ToSteam[K comparable, V, R any](s Steam2[K, V], mapper func(K, V) R) Steam[R]
CollectSteam2ToSteam transforms a Steam2 of key-value pairs into a Steam of type R, using the provided mapper function to convert each key-value pair into a single value of type R.
func Distinct ¶
func Distinct[T comparable](s Steam[T]) Steam[T]
Distinct returns a new Steam containing only the unique elements from the input Steam. It uses a map to track seen elements and filters out duplicates.
func ListOf ¶
ListOf creates a List from a variadic list of elements of type T and returns it as a Steam.
func Mapping ¶ added in v0.2.0
Mapping applies the provided mapper function to each element in the List and returns a new List of type R.
type Steam2 ¶
type Steam2[K comparable, V any] interface { // Filter returns a new Steam2 instance containing only the elements that match the given predicate. // The predicate function takes a key and a value and returns true if the element should be included. Filter(predicate func(K, V) bool) Steam2[K, V] // MapToAny transforms the elements of the Steam2 instance using the provided mapper function, // which takes a key and a value and returns a value of any type. // The result is a new Steam2 instance with the transformed values. MapToAny(mapper func(K, V) any) Steam2[K, any] // MapToInt transforms the elements of the Steam2 instance using the provided mapper function, // which takes a key and a value and returns an int. // The result is a new Steam2 instance with the transformed integer values. MapToInt(mapper func(K, V) int) Steam2[K, int] // MapToString transforms the elements of the Steam2 instance using the provided mapper function, // which takes a key and a value and returns a string. // The result is a new Steam2 instance with the transformed string values. MapToString(mapper func(K, V) string) Steam2[K, string] // FilterMapToAny applies a predicate to filter elements and then maps the remaining elements // using the provided mapper function. The result is a new Steam2 instance with the transformed values. FilterMapToAny(predicate func(K, V) bool, mapper func(K, V) any) Steam2[K, any] // ForEach applies the provided consumer function to each element in the Steam2 instance. // The consumer function takes a key and a value and performs an action for each element. ForEach(consumer func(K, V)) // Peek allows you to inspect each element in the Steam2 instance using the provided consumer function // without modifying the stream. The result is a new Steam2 instance with the same elements. Peek(consumer func(K, V)) Steam2[K, V] // Limit restricts the number of elements in the Steam2 instance to the specified limit. // The result is a new Steam2 instance containing only the first 'limit' elements. Limit(limit int) Steam2[K, V] // AllMatch checks if all elements in the Steam2 instance match the given predicate. // The predicate function takes a key and a value and returns true if the element matches. // It returns true if the stream is empty. AllMatch(predicate func(K, V) bool) bool // AnyMatch checks if any element in the Steam2 instance matches the given predicate. // The predicate function takes a key and a value and returns true if the element matches. // It returns false if the stream is empty. AnyMatch(predicate func(K, V) bool) bool // NoneMatch checks if no elements in the Steam2 instance match the given predicate. // The predicate function takes a key and a value and returns true if the element matches. // It returns true if the stream is empty. NoneMatch(predicate func(K, V) bool) bool // Sorted returns a new Steam2 instance with elements sorted according to the provided comparison function. // The comparison function takes two keys and returns true if the first key is less than the second. Sorted(cmp func(K, K) bool) Steam2[K, V] // GetCompared returns an optional Pair containing the first two elements of the stream compared // using the provided comparison function. If the stream has fewer than two elements, it returns an empty optional. GetCompared(cmp func(K, K) bool) opt.Optional[Pair[K, V]] // Count returns the number of elements in the Steam2 instance. Count() int // Collect gathers all elements in the Steam2 instance into a map with keys of type K and values of type V. Collect() map[K]V // KeysToSteam returns a new Steam instance containing only the keys from the Steam2 instance. KeysToSteam() Steam[K] // ValuesToSteam returns a new Steam instance containing only the values from the Steam2 instance. ValuesToSteam() Steam[V] // ToAnySteam transforms the elements of the Steam2 instance using the provided mapper function, // which takes a key and a value and returns a value of any type. // The result is a new Steam instance with the transformed values. ToAnySteam(mapper func(K, V) any) Steam[any] }
Steam2[K, V] is an interface for a map of elements of type K and V, providing various methods for functional-style processing. Steam2 is a generic interface that provides a fluent API for processing key-value pairs.
func CollectSteamToSteam2 ¶
func CollectSteamToSteam2[K comparable, V, T any](s Steam[T], keyFunc func(T) K, valueFunc func(T) V) Steam2[K, V]
CollectSteamToSteam2 transforms a Steam of type T into a Steam2 of key-value pairs, where keys and values are derived from the provided keyFunc and valueFunc. It collects elements from the input Steam and maps them to a new Steam2 instance.
func GroupBy ¶
func GroupBy[K comparable, V any](s Steam[V], classifier func(V) K) Steam2[K, Steam[V]]
GroupBy groups elements of a Steam by a classifier function that maps each element to a key. It returns a Steam2 where each key corresponds to a Steam of elements that share that key.
func GroupByCounting ¶
func GroupByCounting[K comparable, V any](s Steam[V], classifier func(V) K) Steam2[K, int]
GroupByCounting groups elements of a Steam by a classifier function and counts the occurrences of each key. It returns a Steam2 where each key corresponds to the count of elements that share that key.
func OfMap ¶
func OfMap[K comparable, V any](m map[K]V) Steam2[K, V]
OfMap creates a Steam2 from a map of key-value pairs. The keys and values are derived from the provided map.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
advanced
command
|
|
|
basic
command
|
|
|
groupby
command
|
|
|
zip
command
|
|
|
Package opt provides a generic Optional type that can be used to represent a value that may or may not be present.
|
Package opt provides a generic Optional type that can be used to represent a value that may or may not be present. |