I have some bits of code that I want to execute multiple times so I created few lambda functions. But the problem I run into is that when lamdaX calls inside lambdaY the lambdaY have to be passed, and the number of arguments is limited.
Instead of keeping track what lambda needs to be passed where I tried creating array where I would put all my lambdas and just pass whole array to each one as only parameter. So I would get something like myArray.lambdaX.apply() //pseudocode
but I failed at doing that
Next thing I thought of is creating a simple class - it cant be that hard, right? Well… after a quick research it seem that it is not possible
examlpe (pseudocode-ish) of situation I’m talking about:
val lambdaX = [ |
logInfo( "my.rules", "Doing some stuff!!!" )
]
val timerLambdaX = [ |
var _sunset = new DateTime( Sunset.state.toString )
createTimer( _sunset .plusMinutes( Integer::parseInt( offset.state.toString ) ), [
lambdaX.apply();
])
]
val checkIfAfterSunset = [ |
var _sunset = new DateTime( Sunset.state.toString )
if ( now.isAfter( _sunset ) ) {
logInfo( "my.rules", "Doors should be already closed!" )
lambdaX.apply()
}
else if ( now.isAfter( _sunset.plusMinutes( -120 ) ) ) {
//timers should be set at this point - set them again
logInfo( "my.rules", "Creating timers! (after powerup)" )
timerLambdaX.apply()
}
]
rule "Initial setup"
when
System started
then
createTimer( now.plusMinutes( 2 ), [ |
//wait for everything to initialize and...
checkIfAfterSunset.apply()
]
end
rule "Close doors - set timers"
when
Channel 'astro:sun:myLocation:set#event' triggered END
then
timerLambdaX.apply()
end
At this point I’m confused what to do - is there some other clean solution?