docs/data/core-if.md
A fluent conditional builder that allows chaining If/ElseIf/Else conditions.
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
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
Adds an ElseIf branch to an If/Else chain.
result := lo.If(false, 1).ElseIf(true, 2).Else(3)
// 2
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
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
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