Documentation ¶
Overview ¶
Package fun provides reusable general-purpose functions (Const, Swap, Curry) and data structures (Unit, Pair, Either).
Index ¶
- Variables
- func Cast[A any](i Any) (a A, err error)
- func Compose[A any, B any, C any](f func(A) B, g func(B) C) func(A) C
- func Const[A any, B any](b B) func(A) B
- func ConstUnit[B any](b B) func(Unit) B
- func Curry[A any, B any, C any](f func(a A, b B) C) func(a A) func(b B) C
- func Identity[A any](a A) A
- func Nothing[A any]() A
- func PairV1[A any, B any](p Pair[A, B]) A
- func PairV2[A any, B any](p Pair[A, B]) B
- func RecoverToErrorVar(name string, err *error)
- func RecoverToLog(name string)
- func Swap[A any, B any, C any](f func(a A) func(b B) C) func(b B) func(a A) C
- func ToString[A any](a A) string
- func UnsafeCast[A any](i Any) A
- type Any
- type Pair
- type Unit
Constants ¶
This section is empty.
Variables ¶
var Unit1 = Unit{}
Unit1 is the value of type Unit.
Functions ¶
func Cast ¶ added in v0.2.3
Cast converts interface {} to ordinary type A. It'a simple operation i.(A) represented as a function. In case the conversion is not possible, returns an error.
func ConstUnit ¶
ConstUnit creates a function that will ignore it's Unit input and return the specified value.
func Curry ¶
Curry takes a function that has two arguments and returns a function with two argument lists.
func Identity ¶ added in v0.0.11
func Identity[A any](a A) A
Identity function returns the given value unchanged.
func Nothing ¶ added in v0.2.1
func Nothing[A any]() A
Nothing panics. However, can be used anywhere where type A is needed.
func RecoverToErrorVar ¶ added in v0.2.3
RecoverToErrorVar recovers and places the recovered error into the given variable
func RecoverToLog ¶ added in v0.2.3
func RecoverToLog(name string)
RecoverToLog in case of error just logs it.
func UnsafeCast ¶ added in v0.2.0
UnsafeCast converts interface {} to ordinary type A. It'a simple operation i.(A) represented as a function. In case the conversion is not possible throws a panic.
Types ¶
type Any ¶ added in v0.2.3
type Any interface{}
func CastAsInterface ¶ added in v0.2.0
CastAsInterface casts a value of an arbitrary type as interface {}.