functional

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsFilter added in v0.1.1

func AsFilter[T any](f funcs.FilterFunc[T]) funcs.FilterFunc[T]

AsFilter converts a function conforming to the [FilterFunc] signature to a [FilterFunc] type.

func AsFilterPair added in v0.1.1

func AsFilterPair[K any, V any](f funcs.FilterPairFunc[K, V]) funcs.FilterPairFunc[K, V]

AsFilterPair converts a function conforming to the [FilterPairFunc] signature to a [FilterPairFunc] type.

Types

type Pair added in v0.1.0

type Pair[K any, V any] interface {
	Key() K
	Value() V
}

Pair is a simple interface for key-value pairs. It is used to represent key-value pairs in a way that can be used with functions expecting the Seq type.

func PairOf added in v0.1.0

func PairOf[K any, V any](key K, value V) Pair[K, V]

type Seq

type Seq[T any] iter.Seq[T]

Seq is a new type for iter.Seq that provides functional easy access to other functions of the functional package as methods that can be easily chained together.

func Concat added in v0.1.2

func Concat[T any](seqs Seq[Seq[T]]) Seq[T]

Concat concatenates the provided sequences into a single sequence. This function does return elements in order, starting with the first element of the first sequence and ending with the last element of the last sequence. This does not guarantee that the underlying sequences give a predictable order.

func Map

func Map[I any, O any](in Seq[I], fn funcs.MapFunc[I, O]) Seq[O]

Map applies the provided function to each element of the input sequence, returning a new sequence containing the resulting values.

func OfSeq

func OfSeq[T any](seq iter.Seq[T]) Seq[T]

OfSeq casts an iter.Seq to a Seq for use with the functional package.

func OfSlice added in v0.1.0

func OfSlice[T any](slice []T) Seq[T]

OfSlice converts a slice to a Seq for use with the functional package.

func (Seq[T]) Collect

func (s Seq[T]) Collect() []T

Collect returns the elements of the sequence as a slice.

func (Seq[T]) Filter

func (s Seq[T]) Filter(f funcs.FilterFunc[T]) Seq[T]

Filter filters the input sequence based on the provided filter function, returning a new sequence containing only the elements that pass the filter.

func (Seq[T]) Std added in v0.1.0

func (s Seq[T]) Std() iter.Seq[T]

Std converts the Seq to an iter.Seq for use with other packages.

type Seq2

type Seq2[K comparable, V any] iter.Seq2[K, V]

Seq2 is a new type for iter.Seq2 that provides functional easy access to other functions of the functional package as methods that can be easily chained together.

func OfPairSeq added in v0.1.0

func OfPairSeq[K comparable, V any, S iter.Seq[Pair[K, V]] | Seq[Pair[K, V]]](seq S) Seq2[K, V]

OfPairSeq casts a Seq of key-value pairs to a Seq2 for use with the functional package.

func OfSeq2

func OfSeq2[K comparable, V any](seq iter.Seq2[K, V]) Seq2[K, V]

OfSeq2 casts an iter.Seq2 to a Seq2 for use with the functional package.

func (Seq2[K, V]) AsSeq added in v0.1.0

func (s Seq2[K, V]) AsSeq() Seq[Pair[K, V]]

AsSeq converts a Seq2 to a Seq of key-value pairs implementing the Pair interface

func (Seq2[K, V]) Collect

func (s Seq2[K, V]) Collect() map[K]V

Collect returns the elements of the sequence as a map.

func (Seq2[K, V]) Filter

func (s Seq2[K, V]) Filter(f funcs.FilterPairFunc[K, V]) Seq2[K, V]

Filter filters the input sequence based on the provided filter function, returning a new sequence containing only the elements that pass the filter.

func (Seq2[K, V]) Std added in v0.1.0

func (s Seq2[K, V]) Std() iter.Seq2[K, V]

Std converts the Seq2 to an iter.Seq2 for use with other packages.

Directories

Path Synopsis
Package filter provides support for filtering sequences
Package filter provides support for filtering sequences
Package funcs contains type-definitions and helpers for functions that this module accepts as parameters
Package funcs contains type-definitions and helpers for functions that this module accepts as parameters

Jump to

Keyboard shortcuts

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