# withIt

***withIt(input, function(){** // do something here with this **})***

* **The context object** is available as a receiver (*this*).
* **The return value** is the lambda result.

As *withIt* is not an extension function: the context object is passed as an argument, but inside the lambda, it's available as a receiver (*this*).

We recommend using *withIt* for calling functions on the context object when you don't need to use the returned result. In code, with can be read as "**with this object, do the following**."

```ts
const numbers = mutableListOf("one", "two", "three");

withIt(numbers, function () {
    console.log(`'withIt' is called with argument ${this}`);
    console.log(`It contains ${this.length} elements`);
});
```

You can also use withIt to introduce a helper object whose properties or functions are used for calculating a value.

```ts
const numbers = mutableListOf<string>("one", "two", "three");

const firstAndLast = withIt(numbers, function () {
    return `The first element is ${this.first()}, the last element is ${this.last()}`
});
console.debug(firstAndLast);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://katxupa.gitbook.io/katxupa/get-a-taste-of-katxupa/usage/scope-functions/functions/withit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
