Documentation
¶
Overview ¶
Package fn provides functional programming primitives and different helpers
Index ¶
- func Cast[T any](v any) T
- func Else[T any, M Container[T]](m M, fallback T) T
- func Fold[T, U any, M Container[T]](m M, onNil func() U, onVal func(T) U) U
- func If[T any](cond bool, then T, or T) T
- func Is[T any](v any) bool
- func Must[T any, M Container[T]](m M) T
- func Or[T any](p *T, v T) T
- func OrZero[T any](p *T) T
- func Valid[T comparable](v T) bool
- func ValidReflect[T any](v T) bool
- func Z[T any]() T
- type Container
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fold ¶ added in v0.4.0
Fold pattern matches over a container, calling onNil if invalid, onVal if valid.
func Or ¶
func Or[T any](p *T, v T) T
Or returns first pointer as a value if pointer is not nil.
Else returns fallback T value, which was passed as a second argument.
func OrZero ¶
func OrZero[T any](p *T) T
OrZero validates pointer and returns pointer as a value if pointer is not nil.
Else returns zero T value.
func Valid ¶
func Valid[T comparable](v T) bool
Valid returns whether T is non-zero, where T implements [comparable]
func ValidReflect ¶
ValidReflect - valid through type-casting and [reflectValue]
NOT recommended if not implementing interfaces below, as reflection in Go may be from 25 to 50 times slower than stdlib.
If you really want to, you can check casted interfaces below, and implement one of them to avoid using reflection.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package chain provides helpers for chaining fallible functions in a res.Of pipeline.
|
Package chain provides helpers for chaining fallible functions in a res.Of pipeline. |
|
Package opt implements the Of monad for Go.
|
Package opt implements the Of monad for Go. |
|
Package res implements the Of monad for Go.
|
Package res implements the Of monad for Go. |