interface Foo { fun Bar.foo() } interface Bar {} inline fun myWith(argument: T, lambda: T.() -> R): R { argument.lambda() } fun Any.action(other: Any) { if (this is Foo) { with(other) { this as Bar foo() } } }