Skip to content

Instantly share code, notes, and snippets.

@Odomontois
Created December 6, 2022 08:54
Show Gist options
  • Save Odomontois/3de76151b2cc5f8055acc41100d251df to your computer and use it in GitHub Desktop.
Save Odomontois/3de76151b2cc5f8055acc41100d251df to your computer and use it in GitHub Desktop.
Early return action
func conds(){
earlyReturn := true
defer func(){
if earlyReturn{
action2()
}
}()
prepareForCond1()
if !cond1{
return
}
prepareForCond2()
if!cond2{
return
}
prepareForCond3()
if!cond3(){
return
}
earlyReturn = false
action1()
}
(for {
_ <- Option(prepare_for_cond1()) if cond1
_ = prepareForCond2() if cond2
_ = prepareForCond3() if cond3
} yield action1()
).getOrElse(action2())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment