# ReplaceWith on function with lambda outside parentheses

**URL:** <https://discuss.kotlinlang.org/t/replacewith-on-function-with-lambda-outside-parentheses/18236>\
**Category:** Support\
**Created:** [June 25, 2020, 11:34am UTC](https://discuss.kotlinlang.org/t/replacewith-on-function-with-lambda-outside-parentheses/18236 "2020-06-25T11:34:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rule](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/rule/32/7711_2.png) [@Rule](https://discuss.kotlinlang.org/u/Rule)\
**Post date:** [June 25, 2020, 11:34am UTC](https://discuss.kotlinlang.org/t/replacewith-on-function-with-lambda-outside-parentheses/18236/1 "2020-06-25T11:34:30Z")

</div>

I’m trying to add a ReplaceWith on a function that has the last argument outside of parentheses because it’s a lambda.

So I have this method

```
@Deprecated(
    message = "use extension function from kotlinx",
    replaceWith = ReplaceWith("observe(owner, observer)", "androidx.lifecycle.observe")
)
inline fun <T> LiveData<T>.observe(owner: LifecycleOwner, crossinline observer: (t: T?) -> Unit) {
    observe(owner, Observer {
        observer(it)
    })
}

```

Problem 1  
It puts the lambda back into the parentheses, making me have to do another alt + enter. Also, it adds the type, which isn’t needed because it can be deduced.  
Before:

```
import com.package.extensions.observe

foo.observe(this) {
    doSomething(it)
}

```

After alt + enter:

```
import androidx.lifecycle.observe    
import com.package.extensions.observe

foo.observe<String?>(this, {
    doSomething(it)
})

```

Problem 2: it now has both the old and new import, so the compiler doesn’t know which one to choose. This could be solved if the old import would be removed on alt + enter.

How can I solve these problems?

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [June 26, 2020, 1:45pm UTC](https://discuss.kotlinlang.org/t/replacewith-on-function-with-lambda-outside-parentheses/18236/2 "2020-06-26T13:45:14Z")

</div>

You should open a feature request.  
In general replacing a function with another one with same name in another package might just not work (for ex if there are a few use cases and you replace just some of those, of if there’s an overload which doesn’t get replaced).
