Created
December 6, 2022 08:54
-
-
Save Odomontois/3de76151b2cc5f8055acc41100d251df to your computer and use it in GitHub Desktop.
Early return action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func conds(){ | |
earlyReturn := true | |
defer func(){ | |
if earlyReturn{ | |
action2() | |
} | |
}() | |
prepareForCond1() | |
if !cond1{ | |
return | |
} | |
prepareForCond2() | |
if!cond2{ | |
return | |
} | |
prepareForCond3() | |
if!cond3(){ | |
return | |
} | |
earlyReturn = false | |
action1() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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