Question: I'm using Ktor to make websocket requests.  

The method "websocket(...)" I use takes two lambda expressions.

[![enter image description here](https://i.stack.imgur.com/G9LKE.png)](https://i.stack.imgur.com/G9LKE.png)

So as I only can call one with curly brackets I have to give the other one via a variable. So I tried this:

```kotlin
val request: HttpRequestBuilder.() -> Unit
val socket = ktorHttpClient.webSocket(request = request) {

}

```

The data types fit now but of course it still says "Variable 'request' must be initialized", so I tried to initialize it:

```kotlin
val request: HttpRequestBuilder.() -> Unit = HttpRequestBuilder.()

```

Now the error is gone but inside the last brackets it says "Expecting an expression", what am I missing here?

PS: Maybe there's even somebody who can explain in detail how initialization works when using ".()".

Answer: 
As you said yourself, you need to pass two lambdas. You can do it either directly:

```kotlin
ktorHttpClient.webSocket({ /* request lambda */ }) {
    /* block lambda */
}

```

Or split it as you did:

```kotlin
val request: HttpRequestBuilder.() -> Unit = { /* request lambda */ } 
val socket = ktorHttpClient.webSocket(request) {
    /* block lambda */
}

```

More info on how to initialize lambdas / function types can be found here: <https://kotlinlang.org/docs/lambdas.html#instantiating-a-function-type>
Just use named parameters with lambdas:

```
ktorHttpClient.webSocket(request = {}, block = {})

```