How to create a method that accepts a boolean criteria and a lambda with arguments as a parameter in Java 8?
For Example I have lot of this code.
if(something is true) {
foo("a", "b", 2)
}
if(something else is true) {
bar("hello", 1)
}
Want to create a method that accepts boolean and a lambda so I can factor out all the if checks so I can do something like this?
checkAndCAll(isValid, (a, b, c) -> { if(isValid) foo(a, b, c); })
checkAndCAll(isValid2, (a, b) -> { if(isValid2) bar(a, b, c); })
If there is something even cleaner please suggest