Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 IfThenElse 函数返回泛型结果 #259

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

bigdavidwong
Copy link

添加 IfThenElse 函数

此 PR 添加了一个 IfThenElse 函数,它根据条件返回对应的泛型结果。该函数允许在单行代码中实现类似三元运算符的功能。

功能概述:

  • IfThenElse[T any](condition bool, trueValue, falseValue T) T 根据布尔条件返回 trueValuefalseValue
  • 支持泛型,能够处理任意类型的输入。
  • 请注意,trueValuefalseValue 在传入时即会访问,因此调用方需确保它们的合法性。

示例:

result := IfThenElse(true, "Success", "Failure")
fmt.Println(result) // 输出: Success

huangdawei added 2 commits August 26, 2024 16:51
1. 增加了一个条件判断返回泛型结果的函数;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant