lang

package
v0.0.0-...-fab4c1e Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Package lang provides extensions and utilities to builtin language features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare[T constraints.Ordered](a, b T) int

func Equals

func Equals[T comparable](a, b T) bool

func Equivalent

func Equivalent[T comparable](a, b Iterator[T]) bool

Equivalent compares all elements.

func EquivalentT

func EquivalentT[T any](a, b Iterator[T], eq EqualsFn[T]) bool

EquivalentT compares all elements using the given equality function.

func Sprint

func Sprint[T any](it Iterator[T]) string

Sprint prints all iterator values. Debugging convenience.

func ToList

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

ToList materializes all iterator values into a list.

Types

type CompareFn

type CompareFn[T any] func(a, b T) int

CompareFn defines ordering for arbitrary types, returning -1 if a < b, 0 if a == b and 1 if a > b. This function is not a method to avoid a boxing penalty for every natively-ordered object in a data structure.

func Reverse

func Reverse[T any](fn CompareFn[T]) CompareFn[T]

type EqualsFn

type EqualsFn[T any] func(a, b T) bool

EqualsFn defines equality for arbitrary types. This function is not a method to avoid a boxing penalty for every natively-ordered object in a data structure.

type Iterator

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

Iterator allows a caller-controlled iteration over a set of elements. It is expected to be lazily-computed, such that the cost is proportional to the number of elements consumed.

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

Head limits an iterator to N values lazily.

func Map

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

Map transforms values of an iterator lazily.

func MapIf

func MapIf[T, U any](it Iterator[T], fn func(t T) (U, bool)) Iterator[U]

MapIf transforms selected values of an iterator lazily.

type Optional

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

Optional represents an optional value of type T. Default value is None.

func None

func None[T any]() Optional[T]

func Some

func Some[T any](t T) Optional[T]

func (Optional[T]) String

func (o Optional[T]) String() string

func (Optional[T]) V

func (o Optional[T]) V() (T, bool)

V returns the value. False if not present.

Jump to

Keyboard shortcuts

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