alsoIt

alsoIt(it => { // do something here with it })

  • The context object is available as an argument (it).

  • The return value is the object itself.

alsoIt is useful for performing some actions that take the context object as an argument. Use alsoIt for actions that need a reference to the object rather than its properties and functions, or when you don't want to shadow the this reference from an outer scope.

When you see also in code, you can read it as "and also do the following with the object."

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

numbers
    .alsoIt(it => console.log(`The list elements before adding new one: ${it}`))
    .push("four");

Last updated