Is there a way to limit function invocation using ...
# announcements
e
Is there a way to limit function invocation using something like
fun doSth(action: Mode.() -> Unit)
? But
Mode
contains only functions, no properties. Although it is completely fine to create instance of
Mode
and pass it to
action(mode)
, it just doesn't quite make sense for me to create such a instance.
g
limit function invocation?
e
One example would be one can only invoke
add
,
minus
inside
fun doSth
Copy code
fun doSth(action: Mode.() -> Unit) { ... }
doSth {
  add() // OK
  minus() // OK
  multiple() // Not ok
}
g
mm, maybe do not add multiply to Mode interface?
Or I didn’t get your case
e
That's what I want to do, but I just can't figure out a nice way to do it
g
Imo nice way: use different interface hierarchy depending on case
e
Cause I need to do
Copy code
fun doSth(...) {
  action(mode) // Don't want to pass in mode
}
Cause
Mode
consist of pure functions, I'm just using it for function grouping purpose in this case.
You mean using
interface Mode
instead of
class Mode
?
g
I mean something like that:
Copy code
class/interface Mode {
  fun add()
  fun minus()
}

class MultipleMode: Mode {
   fun multiple()
}
e
I see, that lights me up