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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2021 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this chapter
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)