Hi Everyone, I need suggestion in declarative prog...
# random
m
Hi Everyone, I need suggestion in declarative programming. how I can make my if else code into declarative code
c
Do you have any example of what you're trying to do? An if statement is declarative (at least to me 😄 )
m
Yes.
if(currentTime <= specificTime}{ type = NewType}
i
Copy code
fun <T> T.applyIf(predicate : (T) -> Boolean, action: T.() -> Unit) {
   if (predicate(this)) apply(action)
}
predicate can be lambda or just boolean, lambda is more dynamic (could use param as arg)
If i’ve understand you correctly
m
Yes Right. Thanks Dear @iamthevoid
i
as i see usage of that fun looks like exactly as usage of
if
construction. So think carefully if you really need that DSL way ))
m
Right