# Scope Functions

Published articles for Scope Functions.

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

## Scope functions

DevFeed: [Scope functions](<https://devfeed.tech/articles/scope-functions-39306.md>)

Original publisher: [Read original article](<https://kt.academy/article/fk-scope-functions>)

Published: 2022-09-23T00:05:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [functions](<https://devfeed.tech/topics/functions.md>), [Library](<https://devfeed.tech/topics/library.md>), [object](<https://devfeed.tech/topics/object.md>), [Streams](<https://devfeed.tech/topics/streams.md>), [Back end](<https://devfeed.tech/topics/backend.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [backend](<https://devfeed.tech/tags/backend.md>), [functions](<https://devfeed.tech/tags/functions.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [let](<https://devfeed.tech/tags/let.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [with](<https://devfeed.tech/tags/with.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

A tutorial on Kotlin scope functions, including let, also, apply, and with. It explains how these standard-library extension functions transform or configure objects, presents application examples, and notes that scope-function-heavy code can make debugging harder.

### Source excerpt

What is let, also, apply and with, and how to use them in our applications.

## 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn](<https://devfeed.tech/tags/learn.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [let](<https://devfeed.tech/tags/let.md>), [library](<https://devfeed.tech/tags/library.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>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [variable](<https://devfeed.tech/tags/variable.md>), [visibility](<https://devfeed.tech/tags/visibility.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

A Kotlin tutorial chapter introduces scopes as regions of code where variables, functions, and classes can be declared, then begins explaining Kotlin's five scope functions from the standard library.

### 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.

## Exploring Kotlin's Context Receivers

DevFeed: [Exploring Kotlin's Context Receivers](<https://devfeed.tech/articles/exploring-kotlin-s-context-receivers-25511.md>)

Original publisher: [Read original article](<http://nomisrev.github.io/context-receivers/>)

Author: Simon Vergauwen

Published: 2022-02-17T00:00:00Z

Content type: article

Language: en

Sources: [nomisRev](<https://devfeed.tech/sources/nomisrev.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [ide](<https://devfeed.tech/topics/ide.md>), [context](<https://devfeed.tech/topics/context.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [dsl](<https://devfeed.tech/tags/dsl.md>), [effect](<https://devfeed.tech/tags/effect.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [fp](<https://devfeed.tech/tags/fp.md>), [function](<https://devfeed.tech/tags/function.md>), [ide](<https://devfeed.tech/tags/ide.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [suspend](<https://devfeed.tech/tags/suspend.md>)

### AI overview

A tutorial on Kotlin Context Receivers, introduced as a preview in Kotlin 1.6.20-M1. It explains how additional receivers work, how the compiler handles them, and how they can support scope-based programming patterns such as effect handlers and logging contexts.

### Source excerpt

Last week a long awaited feature was released as a preview in Kotlin 1.6.20-M1. In this blogpost we're going to explore what Context Receivers are, and some benefits and patterns they'll enable. To try it out in your IDE, follow this guide

## 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [context](<https://devfeed.tech/topics/context.md>)

Tags: [comparison](<https://devfeed.tech/tags/comparison.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [readability](<https://devfeed.tech/tags/readability.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>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

### AI overview

This Kotlin tutorial compares with() and run(), explaining that they are nearly identical in compiled behavior and differ mainly in syntax. It highlights the extension-function advantage of safe-call handling for nullable receivers and discusses readability trade-offs.

### 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [guide](<https://devfeed.tech/tags/guide.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.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>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

An overview of Kotlin's with() scope function, including how it accepts a receiver as an argument, makes that receiver available inside a code block, and returns the block's result. It also covers an initialization-and-execution use case and compares with() with related scope functions.

### 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>)

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

### AI overview

A guide to Kotlin's let(), also(), run(), and apply() scope functions. It explains their shared characteristics and distinguishes them by code-block context and return value.

### 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.md>), [code](<https://devfeed.tech/tags/code.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [function](<https://devfeed.tech/tags/function.md>), [guide](<https://devfeed.tech/tags/guide.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>), [library](<https://devfeed.tech/tags/library.md>), [object](<https://devfeed.tech/tags/object.md>), [overview](<https://devfeed.tech/tags/overview.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>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [val](<https://devfeed.tech/tags/val.md>), [variable](<https://devfeed.tech/tags/variable.md>)

### AI overview

An overview of Kotlin's apply() scope function, including its receiver and return value, with examples of using it to initialize objects and configure Android code.

### 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.

## 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: tutorial

Language: en

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

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

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

### AI overview

A Kotlin tutorial explaining the also() scope function. It shows that also() exposes the receiver as the lambda argument, conventionally named it, and returns the receiver object.

### 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.

## Scope Functions

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

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

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-04T02:33:15Z

Content type: article

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [also](<https://devfeed.tech/tags/also.md>), [apply](<https://devfeed.tech/tags/apply.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>), [library](<https://devfeed.tech/tags/library.md>), [programming](<https://devfeed.tech/tags/programming.md>), [receiver](<https://devfeed.tech/tags/receiver.md>), [run](<https://devfeed.tech/tags/run.md>), [scope](<https://devfeed.tech/tags/scope.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

This article explains Kotlin scope functions: commonly used functions in the Kotlin standard library that place an object in a new scope, including also(), apply(), let(), run(), and with().

### Source excerpt

Scope functions consist of the often-used functions from Standard.kt in the Kotlin standard library that take an object and put it into a new scope, such as this or it. also() apply() let() run() (with receiver) with()

## 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: tutorial

Language: en

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

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [extension-function](<https://devfeed.tech/tags/extension-function.md>), [function](<https://devfeed.tech/tags/function.md>), [http](<https://devfeed.tech/tags/http.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.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

This tutorial explains Kotlin's run() extension function, one of the scope functions in the Kotlin standard library. It covers the receiver object, the function's result, and using run() to initialize and execute an object, including an HTTP client example.

### 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: