Is it possible to iterate over statements in a blo...
# getting-started
v
Is it possible to iterate over statements in a block? E.g.
Copy code
{
  someFun()
  "Some Text"
  anything + else
}
In order to "catch" some specific statements
d
I don't understand, do you want to store a
String
representation of each statement in an
Iterable
and filter?
v
Yes, filter them, but I thought of evaluating each statement and checking result of each one, and do some action. E.g. redirect
"Some Text"
into another function. The block is supposed to arrive in lambda (perhaps, there are better ways to get something out of a lambda's body)
k
Are you trying to write a DSL?
v
That's right
k
If so, do it how the Kotlin team itself does it by defining eg.
unaryPlus
, see the guide I linked you.
v
Yes, I saw, there was exactly that approach, so the question arose: is it possible to avoid infix or any other functions to make syntax more readable
k
No it is not, if it was they would have just done that instead.
n
DSLContext.unaryPlus(element: Any) is the cleanest way to define such a thing then ?
k
Yes.