Documentation
¶
Overview ¶
Package cond provides generic, ternary-like conditional functions.
This package offers a concise way to express simple conditional logic in a single expression, avoiding the need for a more verbose if-else block. It provides functions for both eagerly-evaluated values and lazily-evaluated functions.
Example (Eager Evaluation):
// Instead of:
// var status string
// if code == 200 {
// status = "OK"
// } else {
// status = "Error"
// }
status := cond.If(code == 200, "OK", "Error")
Example (Lazy Evaluation):
// The expensive functions are only called when needed. result := cond.IfFunc(isComplex, doComplexCalculation, doSimpleCalculation)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func If ¶
If returns trueVal if the condition is true, and falseVal otherwise. This is a generic, eagerly-evaluated ternary-like expression. Both trueVal and falseVal are evaluated before this function is called.
For lazy evaluation where values are expensive to compute, see IfFunc.
func IfFunc ¶
IfFunc returns the result of trueFn if the condition is true, and the result of falseFn otherwise. This is a generic, lazily-evaluated ternary-like expression. Only the function corresponding to the condition's outcome is executed.
Types ¶
This section is empty.