We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Prototype:
// 'ternary operator' func IfElseAssign[T any](val bool, ifTrue T, ifFalse T) T { if val { return ifTrue } else { return ifFalse } } // 'ternary operator' (lazy production of value) func IfElseAssignFn[T any](val bool, ifTrue func() T, ifFalse func() T) T { if val { return ifTrue() } else { return ifFalse() } } // "adapter" for making values for `IfElseAssignFn` without having to type the full `func () string { return "foo" }` func fn[T any](val T) func() T { return func() T { return val } } func main() { name := "Joonas" powerEstimate := IfElseAssignFn(name == "Joonas", fn(9001), fn(3)) powerEstimate = IfElseAssign(name == "Joonas", 9001, 3) fmt.Printf("Power of %s = %d\n", name, powerEstimate) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Prototype:
The text was updated successfully, but these errors were encountered: