ifelse

package
v0.3.27 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If[T any](condition bool) *ifExpr[T]

用法示例:

result := ifelse.If[string](age < 18).Then("child").
  ElseIf(age < 60).Then("adult").
  ElseIf(age < 120).Then("senior").
  Else("invalid")

func Ternary

func Ternary[T any](condition bool, consequent, alternative T) T

三目条件函数。

入参:

  • condition: 条件。
  • consequent: 条件为真时返回的值。
  • alternative: 条件为假时返回的值。

出参:

  • 若 condition 的为真,将返回 consequent;否则,将返回 alternative。

func TernaryFunc

func TernaryFunc[T any](condition bool, consequentFunc, alternativeFunc func() T) T

Ternary 类似,但返回值支持延迟计算函数。

入参:

  • condition: 条件。
  • consequentFunc: 条件为真时返回的计算函数。
  • alternativeFunc: 条件为假时返回的计算函数。

出参:

  • 若 condition 的为真,将返回 consequentFunc 的计算结果;否则,将返回 alternativeFunc 的计算结果。

Types

This section is empty.

Jump to

Keyboard shortcuts

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