docs/data/core-switch.md
Starts a functional switch/case/default chain using a predicate value.
result := lo.Switch(2).Case(1, "1").Case(2, "2").Default("3")
// "2"
Adds a Case branch to a Switch chain returning a constant result.
result := lo.Switch(1).Case(1, "1").Default("?")
// "1"
Adds a Case branch that lazily computes its result.
result := lo.Switch(2).CaseF(2, func() string {
return "2"
}).Default("?")
// "2"
Completes the Switch chain by providing a default result when no Case matched.
result := lo.Switch(42).Default("none")
// "none"
Function form of Default. Lazily computes the default result when no Case matched.
result := lo.Switch(0).Case(1, "1").DefaultF(func() string {
return "3"
})
// "3"