Skip to main content

Scope and Conditional Functions

  • Chapter
  • First Online:
Beginner's Guide to Kotlin Programming
  • 1387 Accesses

Abstract

Kotlin provides five functions whose sole purpose is to execute a block of code within the context of an instance or an object. When you call such a function on an instance with a lambda expression, it forms a temporary scope (hence the term scope function). In this scope, you can access the instance directly typically using the this reference or in two cases using the it implicit parameter.

There are five higher order scope functions:

  • apply{}, let{}run{}with{}, and also{}

In addition there is the runCartching{} exception handling scope function which will be discussed in the chapter on Error and Exception Handling.

Each of these scope functions and their typical usages will be discussed in the remainder of this chapter.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 44.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 59.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2021 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Hunt, J. (2021). Scope and Conditional Functions. In: Beginner's Guide to Kotlin Programming. Springer, Cham. https://doi.org/10.1007/978-3-030-80893-8_11

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-80893-8_11

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-80892-1

  • Online ISBN: 978-3-030-80893-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics