# scope function

A Kotlin scope function executes a block of code within an object's temporary context, allowing access to the object without its name.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Practical Kotlin Deep Dive: Master Kotlin Internals and Ace Your Next Technical Interview

DevFeed: [Practical Kotlin Deep Dive: Master Kotlin Internals and Ace Your Next Technical Interview](<https://devfeed.tech/articles/practical-kotlin-deep-dive-master-kotlin-internals-and-ace-your-next-technical-interview-25926.md>)

Original publisher: [Read original article](<https://skydoves.medium.com/practical-kotlin-deep-dive-master-kotlin-internals-and-ace-your-next-technical-interview-33ff30f91493?source=rss-9bb203a4ab2e------2>)

Author: Jaewoong Eum

Published: 2026-02-18T03:55:53Z

Content type: article

Language: en

Sources: [Jaewoong Eum](<https://devfeed.tech/sources/stories-by-jaewoong-eum-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Learning](<https://devfeed.tech/topics/learning.md>), [coroutines-flow](<https://devfeed.tech/topics/coroutines-flow.md>), [runBlocking](<https://devfeed.tech/topics/runblocking.md>), [software-development](<https://devfeed.tech/topics/software-development.md>), [scope function](<https://devfeed.tech/topics/scope-function.md>), [Safe-Call Operator](<https://devfeed.tech/topics/safe-call-operator.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [book](<https://devfeed.tech/tags/book.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [course](<https://devfeed.tech/tags/course.md>), [data-class](<https://devfeed.tech/tags/data-class.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [deep-dive](<https://devfeed.tech/tags/deep-dive.md>), [insights](<https://devfeed.tech/tags/insights.md>), [interactive](<https://devfeed.tech/tags/interactive.md>), [internals](<https://devfeed.tech/tags/internals.md>), [interview](<https://devfeed.tech/tags/interview.md>), [keep](<https://devfeed.tech/tags/keep.md>), [knowledge](<https://devfeed.tech/tags/knowledge.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [language](<https://devfeed.tech/tags/language.md>), [lazy](<https://devfeed.tech/tags/lazy.md>), [performance](<https://devfeed.tech/tags/performance.md>), [programming](<https://devfeed.tech/tags/programming.md>), [technical-interview](<https://devfeed.tech/tags/technical-interview.md>)

### AI overview

Practical Kotlin Deep Dive teaches Kotlin internals through bytecode, compiler references, and KEEP proposals across 70 topics in six chapters. The excerpt highlights practical mechanisms: lambda objects explain the role of `inline`; coroutine cancellation exceptions can be swallowed by broad catches; and `kotlinx-serialization` generates serializers at compile time rather than relying on reflection. It also contrasts KAPT, which generates Java stubs for annotation processors, with KSP, which reads Kotlin symbols directly and is described as at least twice as fast in many projects. The companion course adds runnable playgrounds and 158 quizzes; the book and course share the same topic coverage, while the course includes practice and a completion certificate. These points describe the material presented in the supplied excerpt.

### Source excerpt

Most Kotlin developers can write a data class, launch a coroutine, or use lazy without thinking twice. These features work, the code compiles, and the app runs. But there is a gap between knowing how to use Kotlin and understanding what the compiler actually does with your code. That gap is where performance intuition, debugging skill, and technical interview confidence come from. Practical Kotlin Deep Dive is a book designed to close that gap, covering 70 Kotlin topics across 492 pages with bytecode decompilations, compiler source code references, and KEEP proposal analysis that reveal the machinery behind every feature you use daily. In this article, you'll explore what the book and its companion course cover, walking through each of the six chapters with examples of the insights you'll find inside. You'll see how the book approaches topics differently from typical Kotlin resources, what the "Pro Tips for Mastery" sections reveal about internal mechanisms, and how the interactive course format turns that knowledge into verified understanding through Code Playgrounds and 158 quiz questions. Beyond the syntax: Why internals matter Knowing that lazy caches a value on first access is useful. Knowing that the default lazy implementation uses double checked locking with a synchronized block, and that you can switch to a lock free compareAndSet strategy by passing LazyThreadSafetyMode.PUBLICATION, is the difference between using a feature and making informed decisions about it. The same applies across the language. Understanding that every lambda passed to a higher order function creates a Function object on the heap explains why inline exists. Seeing a data class decompiled into seven generated methods explains what the compiler is doing on your behalf. This is the approach Practical Kotlin Deep Dive takes throughout. Rather than describing what Kotlin features do, it examines how they work internally, what bytecode they produce, what design trade-offs the language desi

## Scopes and Scope Functions

DevFeed: [Scopes and Scope Functions](<https://devfeed.tech/articles/scopes-and-scope-functions-25063.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-scopes-and-scope-functions/>)

Author: author@typealias.com (Dave Leeds)

Published: 2022-08-22T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [extension](<https://devfeed.tech/tags/extension.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [let](<https://devfeed.tech/tags/let.md>), [programming](<https://devfeed.tech/tags/programming.md>), [run](<https://devfeed.tech/tags/run.md>), [scope](<https://devfeed.tech/tags/scope.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [shadowing](<https://devfeed.tech/tags/shadowing.md>), [variables](<https://devfeed.tech/tags/variables.md>), [visibility](<https://devfeed.tech/tags/visibility.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

The excerpt introduces Kotlin scopes as sections of code where variables, functions, classes, and other declarations can be made. Even a variable added to a new Kotlin file belongs to that file's scope. It sets up a later discussion of the five scope functions in Kotlin's standard library but does not describe how those functions work.

### Source excerpt

In the last chapter, we learned how to create extension functions, which can be called using dot notation. In this chapter, we'll learn about scope functions, which are five particular functions that Kotlin gives us in its standard library. Before we can understand scope functions, though, it helps to first understand scopes. Introduction to Scopes In Kotlin, a scope is a section of code where we can declare new variables, functions, classes, and more.

## An opinionated guide on how to make your Kotlin code fun to read and joy to work with

DevFeed: [An opinionated guide on how to make your Kotlin code fun to read and joy to work with](<https://devfeed.tech/articles/an-opinionated-guide-on-how-to-make-your-kotlin-code-fun-to-read-and-joy-to-work-with-25931.md>)

Original publisher: [Read original article](<https://proandroiddev.com/an-opinionated-guide-on-how-to-make-your-kotlin-code-fun-to-read-and-joy-to-work-with-caa3a4036f9e?source=rss-7a8d96da8cb6------2>)

Author: Gabor Varadi

Published: 2021-02-15T06:16:05Z

Content type: tutorial

Language: en

Sources: [Gabor Varadi](<https://devfeed.tech/sources/stories-by-gabor-varadi-on-medium.md>)

Topics: [Code quality](<https://devfeed.tech/topics/code-quality.md>), [scope function](<https://devfeed.tech/topics/scope-function.md>), [Safe-Call Operator](<https://devfeed.tech/topics/safe-call-operator.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [if statement](<https://devfeed.tech/topics/if-statement.md>), [code beautification](<https://devfeed.tech/topics/code-beautification.md>), [pretty printing](<https://devfeed.tech/topics/pretty-printing.md>), [smart cast](<https://devfeed.tech/topics/smart-cast.md>), [constructor](<https://devfeed.tech/topics/constructor.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [code-style](<https://devfeed.tech/tags/code-style.md>), [guide](<https://devfeed.tech/tags/guide.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [style](<https://devfeed.tech/tags/style.md>)

### AI overview

The guide favors Kotlin code whose intent and types stay easy to read as code evolves. Put constructor properties on separate lines when there are multiple arguments, use named lambda parameters in multi-line or chained expressions, and name multiple callback lambdas. Reserve `let` for simple assignments or returns; avoid using it as general control flow or replacing `if`/`else` with `x?.let {} ?: run {}`. Prefer early returns with the Elvis operator when there is no alternate branch, explicit return types on public non-override functions, `val` where mutation is unnecessary, and non-null parameters when null is not meaningful. Use named data classes rather than positional decomposition or tuple return types when fields carry distinct meanings. The author also recommends read-only `List` types instead of exposing mutable list types, built-in collection operations instead of equivalent loops, and choosing function types, `fun interface`, or regular interfaces according to whether callbacks need a name or multiple methods. These are presented as style recommendations, with some preferences explicitly personal or situational.

### Source excerpt

I've been meaning to write this article in a while. Hopefully, the following tips and style recommendations (in no particular order) will help you write better Kotlin! Let's get on with it, shall we? For 2 or more constructor arguments, prefer not to keep the properties on the same line as the class name in the constructor definitionclass MyClass( val a: A, val b: B, ): MyParentClass(a, b), MyInterface { // ... } This format is preferable, because when adding the 3rd argument, important bits (such as a possible base class or interface) can appear too far on the right side of the screen. Listing them one after the other (including the trailing comma since 1.4.21+) allows for better readability and extensibility (reducing the chance of causing merge conflicts with future code changes, for example). Prefer to use the scoping function 'let' only in assignments or return statements, but NOT as general control flow, or a "quick rename to 'it'" Oftentimes, Kotlin code tends to do something like this: fun myMethod(nullableA: A?) { nullableA?.let { // no it.x() // no it.y() // no it.z() // no } } (Note: in a method like this, A? could be replaced with A to take advantage of typed nullability, this is just an example.) To allow better maintainability and readability, we should instead prefer to only use ?.let { in simple assignments, or return statements, but not as general control flow. For example, the following chain is easy to understand: val protoClass = savedInstanceState?.getByteArray("protoValue") ?.let { ProtoClass.parseFrom(it) } However, in this case, ?.let { is part of an assignment. Also, while ?.let { can be chained with a ?: to provide a default value (especially in combination with takeIf) it shouldn't be used to execute side-effects (also is more suitable for that). In fact, it needs to be said: x?.let {} ?: run {} is NOT a general purpose replacement for if-else statements and null-checks, and should never be used in this particular format for that purpose!

## With the receiver in scope

DevFeed: [With the receiver in scope](<https://devfeed.tech/articles/with-the-receiver-in-scope-26030.md>)

Original publisher: [Read original article](<https://elizarov.medium.com/with-the-receiver-in-scope-7b52bdcca6e9?source=rss-4762e889f8fc------2>)

Author: Roman Elizarov

Published: 2020-07-01T14:33:13Z

Content type: article

Language: en

Sources: [Roman Elizarov](<https://devfeed.tech/sources/stories-by-roman-elizarov-on-medium.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Object-oriented programming (OOP)](<https://devfeed.tech/topics/oop.md>)

Tags: [api-design](<https://devfeed.tech/tags/api-design.md>), [context](<https://devfeed.tech/tags/context.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scopes](<https://devfeed.tech/tags/scopes.md>), [software-development](<https://devfeed.tech/tags/software-development.md>)

### AI overview

Kotlin's `with` scope function groups operations on one object and avoids repeating its name, while receiver lambdas can make general-purpose code less clear. The excerpt contrasts `filter { it.firstName == name }`, which makes the compared property explicit, with a receiver-lambda form where it is ambiguous whether `Person.firstName` or `Person.name` is being compared. It argues that readability matters more than brevity: use receiver lambdas for DSLs and type-safe builders, where the receiver provides a deliberately chosen context, and use `with`, `run`, or `apply` idiomatically when they match the code's intent rather than solely to shorten it. The excerpt notes that `with` is a standard-library function enabled by Kotlin's receiver-lambda feature.

### Source excerpt

Photo by Ben Wicks on UnsplashRepetitio est mater studiorum (Latin, repetition is the mother of all learning). Repetition is great for study, but a bane of software development. Repetitive code is boring and error-prone. Let's look at a hypothetical example inspired by imperative UI frameworks that are still being used a lot nowadays, even though their heyday is past. We might find ourselves having to write code like this: applicationWindow.title = "Just an example" applicationWindow.position = FramePosition.AUTO applicationWindow.content = createContent() applicationWindow.show() Referencing applicationWindow object over and over again is very explicit but it is not pretty. We can make this code better using with scope function from the Kotlin standard library: with(applicationWindow) { // this: ApplicationWindow title = "Just an example" position = FramePosition.AUTO content = createContent() show() } This code now has more lines, but the number of lines is not the key metric you should be looking at when judging the code. The code looks cleaner. It groups all the initialization of the applicationWindow object into a separate, syntactically distinct block. It directly represents the developer's intent to perform all of these actions on applicationWindow together. The block of code inside of with(x) { ... } is easily recognizable by any developer trained in a mainstream object-oriented language -- it is similar to the code you encounter inside a method of the corresponding class where this refers to the method's receiver object and all unqualified references like title refer to this object's properties and methods. In the Kotlin programming language writing a method is not the only way to get access to object members without having to repeat the object's name. Kotlin has support for extension functions that allow us to write a method-like looking code outside of the class body: fun ApplicationWindow.configure() { // this: ApplicationWindow title = ... // no need to

## Choosing between with() and run()

DevFeed: [Choosing between with() and run()](<https://devfeed.tech/articles/choosing-between-with-and-run-25032.md>)

Original publisher: [Read original article](<https://typealias.com/guides/choosing-between-with-and-run/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-14T01:23:30Z

Content type: comparison

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>)

Tags: [bytecode](<https://devfeed.tech/tags/bytecode.md>), [decompiler](<https://devfeed.tech/tags/decompiler.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [intellij](<https://devfeed.tech/tags/intellij.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [nulls](<https://devfeed.tech/tags/nulls.md>), [programming](<https://devfeed.tech/tags/programming.md>), [readability](<https://devfeed.tech/tags/readability.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [run](<https://devfeed.tech/tags/run.md>), [safe-call-operator](<https://devfeed.tech/tags/safe-call-operator.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

Kotlin's `with()` and receiver `run()` both expose the object as `this` inside the block and return the block's result; the excerpt says they compile almost identically. The key practical difference shown is that extension `run()` can be called with a safe-call (`?.`), so a null receiver skips the block and yields null. Passing a nullable value to `with()` still executes its block, so it does not provide the same null interception. The excerpt begins a readability discussion but cuts off before stating its conclusion.

### Source excerpt

In Kotlin's standard library, the Standard.kt file contains a number of scope functions that put a receiver object into a new scope as either this or as an argument (e.g., it). The with() function tends to be a bit of an outlier. The others are all extension functions, so they're invoked on an object. with(), on the other hand, takes its receiver (the object that it's operating upon) as an argument.

## with() (scope function)

DevFeed: [with() (scope function)](<https://devfeed.tech/articles/with-scope-function-25030.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/with/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-14T01:00:44Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>), [function](<https://devfeed.tech/topics/function.md>), [Parameter](<https://devfeed.tech/topics/parameter.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [argument](<https://devfeed.tech/tags/argument.md>), [block](<https://devfeed.tech/tags/block.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [function](<https://devfeed.tech/tags/function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [let](<https://devfeed.tech/tags/let.md>), [programming](<https://devfeed.tech/tags/programming.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [run](<https://devfeed.tech/tags/run.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [string](<https://devfeed.tech/tags/string.md>), [use-case](<https://devfeed.tech/tags/use-case.md>), [variable](<https://devfeed.tech/tags/variable.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

Kotlin's with() accepts an object as its first argument and makes it available as `this` inside the block; the function returns the block's result. It is not an extension function, unlike the related scope functions named in the source. The excerpt describes with() as functionally equivalent to the receiver form of run() and suitable for initializing an object and then operating on it. It notes that choosing between with() and run() involves trade-offs, but does not specify them.

### Source excerpt

Overview The with() function is a scope function found in the Kotlin standard library. Unlike let(), also(), run() with receiver, and apply(), with() is not an extension function, but instead accepts the receiver as an argument. Example val size = with("Hello") { println(this) length } In this example, the string "Hello" is printed, and then its length is assigned to the size variable. Characteristics When the with() extension function executes:

## Understanding Kotlin's let(), also(), run(), and apply()

DevFeed: [Understanding Kotlin's let(), also(), run(), and apply()](<https://devfeed.tech/articles/understanding-kotlin-s-let-also-run-and-apply-25044.md>)

Original publisher: [Read original article](<https://typealias.com/guides/understanding-let-also-run-apply/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-08T00:00:00Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [let](<https://devfeed.tech/tags/let.md>), [programming](<https://devfeed.tech/tags/programming.md>), [run](<https://devfeed.tech/tags/run.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>)

### AI overview

The excerpt explains that Kotlin's let(), also(), run(), and apply() are inline extension functions that take a code block. They differ by the block's context and the function's return value: the receiver can be available as the lambda argument (with the original context preserved) or become the block receiver; the function returns either the receiver object or the block's result. The excerpt illustrates these distinctions with apply() and another function, but the code and function names are missing from the supplied text, so it does not support a complete mapping of all four functions to the two dimensions.

### Source excerpt

Kotlin's standard library includes some often-used scope functions that are so abstract that even those who have been programming in Kotlin for a while can have a hard time keeping them straight. In this guide, we're going to clarify four of these scope functions in particular - let(), also(), run(), and apply(). By the end of this guide, you'll have a framework for understanding them and should have a good idea of which one is most applicable in different scenarios.

## apply() (scope function)

DevFeed: [apply() (scope function)](<https://devfeed.tech/articles/apply-scope-function-25008.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/apply/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-04T20:06:46Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>), [function](<https://devfeed.tech/topics/function.md>), [Boilerplate](<https://devfeed.tech/topics/boilerplate.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [example](<https://devfeed.tech/tags/example.md>), [function](<https://devfeed.tech/tags/function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [object](<https://devfeed.tech/tags/object.md>), [programming](<https://devfeed.tech/tags/programming.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>)

### AI overview

Kotlin's standard-library apply() runs a block with the receiver object available as `this`, then returns that same object. This makes it useful for initializing or configuring an object after creation: several setup calls can be grouped in the block without repeating the receiver on each line. The excerpt also points to other Kotlin scope functions as alternatives but does not compare their behavior.

### Source excerpt

Overview The apply() function is a commonly-used scope function defined in the Kotlin standard library. It's frequently used for initializing an object after instantiation. Example val size = "Hello".apply { println(this) }.length In this example, the string "Hello" is printed, and then its length is assigned to the size variable. Characteristics When the apply() extension function executes: the receiver object that .apply() is called upon is available as this the result will be the receiver object Initializing an Object It's common to use apply() to initialize an object after it's been created.

## let() (scope function)

DevFeed: [let() (scope function)](<https://devfeed.tech/articles/let-scope-function-25019.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/let/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-04T19:54:18Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>), [function](<https://devfeed.tech/topics/function.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>)

Tags: [argument](<https://devfeed.tech/tags/argument.md>), [block](<https://devfeed.tech/tags/block.md>), [code](<https://devfeed.tech/tags/code.md>), [example](<https://devfeed.tech/tags/example.md>), [extension](<https://devfeed.tech/tags/extension.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [let](<https://devfeed.tech/tags/let.md>), [library](<https://devfeed.tech/tags/library.md>), [object](<https://devfeed.tech/tags/object.md>), [programming](<https://devfeed.tech/tags/programming.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [scope](<https://devfeed.tech/tags/scope.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [string](<https://devfeed.tech/tags/string.md>)

### AI overview

Kotlin's `let()` makes its receiver available as the lambda argument (by default, `it`) and returns the lambda's result, so it is often used to transform an object. For transformations to a property or function result, the excerpt suggests accessing that member directly or using an extension function; the latter can handle nulls with a safe-call operator. Unlike `map()`, which operates on items in a collection, `let()` operates on the object itself, treating a collection as a whole.

### Source excerpt

Overview The let() function is one of a handful of scope functions defined in the Kotlin standard library. Example val size = "Hello".let { println(it) it.length } In this example, the string "Hello" is printed, and then its length is assigned to the size variable. Characteristics When the let() extension function executes: the receiver object that .let() is called upon is available as the lambda argument - by default, named it the result of let() will be the result of the code block passed to it Transformation The let() method is frequently used to transform an object.

## also() (scope function)

DevFeed: [also() (scope function)](<https://devfeed.tech/articles/also-scope-function-25007.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/also/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-04T19:41:30Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>)

Tags: [function](<https://devfeed.tech/tags/function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [object](<https://devfeed.tech/tags/object.md>), [pass](<https://devfeed.tech/tags/pass.md>), [pattern](<https://devfeed.tech/tags/pattern.md>), [programming](<https://devfeed.tech/tags/programming.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [use-case](<https://devfeed.tech/tags/use-case.md>)

### AI overview

Kotlin's `also()` (introduced in Kotlin 1.1) runs a lambda with the receiver available as its argument, `it` by default, then returns that receiver. The example prints "Hello" inside the lambda and assigns the string's length to a variable afterward. The excerpt also identifies passing a new, empty object to another function for initialization and then evaluating its properties as a use case. It mentions a comparison guide to other scope functions but provides no details about their differences.

### Source excerpt

Overview The also() function is a scope function that was introduced in Kotlin 1.1. Example val size = "Hello".also { println(it) }.length In this example, the string "Hello" is printed, and then its length is assigned to the size variable. Characteristics When the also() extension function executes: the receiver object that .also() is called upon is available as the lambda argument - by default, named it the result will be the receiver object Create, Pass, and Evaluate A prime use case for also() is the pattern where you need to pass an empty object to another function for initialization.

## run() with receiver (scope function)

DevFeed: [run() with receiver (scope function)](<https://devfeed.tech/articles/run-with-receiver-scope-function-25022.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/run-with-receiver/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-03T20:04:25Z

Content type: article

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [scope function](<https://devfeed.tech/topics/scope-function.md>)

Tags: [http-client](<https://devfeed.tech/tags/http-client.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [run](<https://devfeed.tech/tags/run.md>), [scope-function](<https://devfeed.tech/tags/scope-function.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>)

### AI overview

Kotlin's extension run() makes the receiver available inside its block and returns the block's result. The excerpt illustrates using it to print a string and return its length, and describes using it to configure an object, such as adding query parameters to a hypothetical HTTP client, immediately before executing it. In that case the configured object need not be assigned if it is not used afterward. The excerpt distinguishes this extension function from another run() in the standard library but does not provide further comparison.

### Source excerpt

Overview There are two different run() functions defined in Standard.kt in the Kotlin standard library, among a handful of scope functions that are frequently used in Kotlin programming. This article describes the one that's an extension function. Example val size = "Hello".run { println(this) this.length } In this example, the string "Hello" is printed, and then its length is assigned to the size variable. Characteristics When the run() extension function executes: