mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.7 KiB
1.7 KiB
name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
| name | slug | sourceRef | category | subCategory | playUrl | variantHelpers | similarHelpers | position | signatures | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| If/Else | if-else | condition.go#L31 | core | condition | https://go.dev/play/p/WSw3ApMxhyW |
|
|
10 |
|
A fluent conditional builder that allows chaining If/ElseIf/Else conditions.
If
Starts a fluent If/ElseIf/Else chain. Returns a builder that can be completed with ElseIf, Else, etc.
result := lo.If(true, 1).Else(3)
// 1
IfF
Function form of If. Lazily computes the initial result when the condition is true.
result := lo.IfF(true, func() int {
return 1
}).Else(3)
// 1
ElseIf
Adds an ElseIf branch to an If/Else chain.
result := lo.If(false, 1).ElseIf(true, 2).Else(3)
// 2
ElseIfF
Function form of ElseIf. Lazily computes the branch result when the condition is true.
result := lo.If(false, 1).ElseIfF(true, func() int {
return 2
}).Else(3)
// 2
Else
Completes the If/Else chain by returning the chosen result or the default provided here.
result := lo.If(false, 1).ElseIf(false, 2).Else(3)
// 3
ElseF
Function form of Else. Lazily computes the default result if no previous branch matched.
result := lo.If(false, 1).ElseIf(false, 2).ElseF(func() int {
return 3
})
// 3