Title: Theory / Unimportant / CS / Programming / Kotlin / Library / scope
On every note of this deck, unless a note says otherwise:
Page: https://kotlinlang.org/docs/scope-functions.html#function-selection

Name: A scope function
Definition: A function whose sole purpose is to execute a block of code within the context of an object.
Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Context: Kotlin
Example: let, run, with, apply, and also

Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Syntactic sugar: obj.let(fn)
Implementation: fn(obj)
Language: Kotlin
Intuition: Avoid to introduce a name for obj

Question: To execute a lambda on a non-null object, which scoped function to use?
Answer: let
Chapter: Kotlin

Question: To introduce an expression as a variable in local scope, which scoped function to use?
Answer: let
Chapter: Kotlin

Question: To configure an object, which scoped function to use?
Answer: apply
Chapter: Kotlin

Question: To configure an object and compute the result, which scoped function to use?
Answer: run
Chapter: Kotlin

Question: To run a statement where an expression is required, which scoped function to use?
Answer: run
Chapter: Kotlin

Question: To have additional effect to a computed value, which scoped function to use?
Answer: also
Chapter: Kotlin

Question: To group function calls on an object, which scoped function to use?
Answer: with
Chapter: Kotlin

Question: What differs between various scope functions
Answer: the way to refer to the context object
Chapter: Kotlin
Answer2: the return value

Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Syntactic sugar: obj.also(fn)
Implementation: obj.let {
  fn(obj)
  return obj
 }
Language: Kotlin

Question: Advantage of scope function where context is `this`
Answer: no need to add an explicit name to represent the context object
Chapter: Kotlin

Question: Advantage of scope function where context is `it`
Answer: this do not have to hide any single variable.
Chapter: Kotlin

Question: Advantage of scope function returning original value
Answer: allow to chain call on the same object
Chapter: Kotlin
Answer2: allow to create an object, apply work to it, and return the object

Question: Advantage of scope function returning result of computation
Answer: allow to do a computation witohut having to introduce a name for intermediate value
Chapter: Kotlin

Instruction: with(object,fn)
object.run(fn)
Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Language: Kotlin
Returns: the result of fn, where `this` is `object`

Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Syntactic sugar: run(fn)
Implementation: fn()
Language: Kotlin

Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Syntactic sugar: object.apply(fn)
Implementation: object.run {
  this.run(fn)
  return this
}
Language: Kotlin

Instruction: object.takeIf(pred)
Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Language: Kotlin
Returns: object if pred(object), otherwise null

Instruction: object.takeUnless(pred)
Page: https://kotlinlang.org/docs/scope-functions.html#function-selection
Language: Kotlin
Returns: null if pred(object), otherwise object

Question: What is the point of takeIf/takeUnless
Answer: use a chain, and filter, using .?, sending to null if some hypothesis does not hold
Context: Kotlin