fx

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 2 Imported by: 2

README

fx: Functional utilities for Go

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](it Iterator[T], pred func(v T) bool) bool

func Any

func Any[T any](it Iterator[T], pred func(v T) bool) bool

func Reduce

func Reduce[T, U any](it Iterator[T], init U, fn func(acc U, v T) U) U

func ToMap

func ToMap[K comparable, V any](it Iterator[Pair[K, V]]) map[K]V

func ToSlice

func ToSlice[T any](it Iterator[T]) []T

func TryMap

func TryMap[K comparable, V any](it Iterator[Result[Pair[K, V]]]) (map[K]V, error)

func TrySlice

func TrySlice[T any](it Iterator[Result[T]]) ([]T, error)

Types

type Iterator

type Iterator[T any] interface {
	Value() T
	Next() bool
}

func Concat

func Concat[T any](iters ...Iterator[T]) Iterator[T]

func ConcatMany

func ConcatMany[T any](iters Iterator[Iterator[T]]) Iterator[T]

func Empty

func Empty[T any]() Iterator[T]

func FMap

func FMap[T, U any](it Iterator[T], fn func(v T) (U, bool)) Iterator[U]

func Filter

func Filter[T any](it Iterator[T], fn func(v T) bool) Iterator[T]

func IterList

func IterList[T any](ts List[T]) Iterator[T]

func IterMap

func IterMap[K comparable, V any](m map[K]V) Iterator[Pair[K, V]]

func IterSet

func IterSet[T comparable](s Set[T]) Iterator[T]

func IterSlice

func IterSlice[T any](ts []T) Iterator[T]

func Map

func Map[T, U any](it Iterator[T], fn func(v T) U) Iterator[U]

func MinRange

func MinRange(min int) Iterator[int]

func OfType

func OfType[T, U any](it Iterator[T]) Iterator[U]

func Only

func Only[T any](v T) Iterator[T]

func Range

func Range(min, max int) Iterator[int]

func Sorted

func Sorted[T any](it Iterator[T], less func(a, b T) bool) Iterator[T]

func Take

func Take[T any](it Iterator[T], n int) Iterator[T]

type List

type List[T any] interface {
	Len() int
	At(i int) T
}

func AsList

func AsList[T any](ts []T) List[T]

type Pair

type Pair[T, U any] struct {
	Fst T
	Snd U
}

func NewPair

func NewPair[T, U any](fst T, snd U) Pair[T, U]

func (Pair[T, U]) Unpack added in v0.1.6

func (p Pair[T, U]) Unpack() (T, U)

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

func Err

func Err[T any](e error) Result[T]

func OK

func OK[T any](v T) Result[T]

func Try

func Try[T any](v T, e error) Result[T]

func (Result[T]) Unpack

func (r Result[T]) Unpack() (T, error)

type Set

type Set[T comparable] map[T]struct{}

func ToSet

func ToSet[T comparable](it Iterator[T]) Set[T]

func TrySet

func TrySet[T comparable](it Iterator[Result[T]]) (Set[T], error)

func (Set[T]) Add

func (s Set[T]) Add(v T)

func (Set[T]) In

func (s Set[T]) In(v T) bool

Jump to

Keyboard shortcuts

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