libprisma

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[S ~[]Result[T], T any](s S) ([]T, error)

Collect takes a slice of Result[T] and returns a slice of T or the first error encountered

func MapValToKey

func MapValToKey[K comparable, V comparable](m map[K]V) map[V]K

MapValToKey takes a map with keys of type K and values of type V, and returns a new map with keys and values swapped. The values in the original map should be comparable.

func Sieve

func Sieve[S ~[]Result[T], T any](s S) ([]T, []error)

Sieve takes a slice of Result[T] and returns a slice of T with the errors removed and a slice of errors if any

func Stream

func Stream[S ~[]T, T any](ch chan T, s ...S)

Stream takes many slices of T and emits each element in the slices in order on the channel `ch`, closing the channel when done

func StreamReader

func StreamReader(ch chan *StreamedChunk, r io.Reader, chunkSize int)

func StreamingSwitch

func StreamingSwitch[T any](s chan T, sinkA chan T, sinkB chan T, f func(T) bool)

StreamingSwitch takes a channel of T and two channels of T and a function that returns a bool, it will apply `f` to each T in `s` and will switch each T from `s` into one of two channels based on the result of `f` until `s` is closed

func Switch

func Switch[S ~[]T, T any](s S, f func(T) bool) ([]T, []T)

Switch takes a slice of T and a function that returns a bool, it will apply `f` to each T in `s` and will switch T into one of two slices based on the result of `f`

Types

type Result

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

Result is a generic type that can hold a value of type T or an error

func Err

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

func Map

func Map[S ~[]T, T any](s S, f func(T) Result[T]) []Result[T]

Map takes a slice of T and a function that returns a Result[T] applies `f` to `s` and returns a slice of Result[T]

func May

func May[T any](v T, err error) Result[T]

May wraps a call to some function that returns value or err and creates a result

func Ok

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

func (Result[T]) IsErr

func (r Result[T]) IsErr() bool

IsErr returns true if the Result has an error

func (Result[T]) Unwrap

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

Unwrap returns the value and error of the Result in the usual Go way

func (Result[T]) ValueOr

func (r Result[T]) ValueOr(def T) T

ValueOr returns the value if there is no error, otherwise returns the default value

func (Result[T]) ValueOrFunc

func (r Result[T]) ValueOrFunc(f func() T) T

ValueOrFunc returns the value if there is no error, otherwise returns the result of the function `f`

func (Result[T]) ValueOrPanic

func (r Result[T]) ValueOrPanic() T

ValueOrPanic returns T if there is no error, otherwise panics

type StreamedChunk

type StreamedChunk struct {
	Chunk []byte
	Read  int
	Done  bool
	Err   error
}

Directories

Path Synopsis
kdf

Jump to

Keyboard shortcuts

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