So this is really more of an XY Problem. You currently implement something in a global lambda, but is that the best approach to achieve what you are trying to with that lambda? In my experience the answer is probably not. Global lambdas are a code smell to me and there are only a few specific circumstances where they should be used.
Having said that, there might be other options. For example, Design Pattern: Separation of Behaviors. Another approach could be to put the code into a Script and use the “Other Rules → Run another rule” to call it. Maybe this is a good opportunity to start exploring one of the other supported languages where you can have libraries (OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules).