title: What's the real intention behind Kotlins also scope function
body: <p>I'm asking myself what the language designers intention behind the also <code>scope</code> function was and if almost everyone is misusing it. </p>
  
  <p>If you search here on stack overflow for examples of Kotlins scope functions, you'll end up with this accepted answer: <a href="https://stackoverflow.com/a/45977254/5122729">https://stackoverflow.com/a/45977254/5122729</a></p>
  
  <p>The given answer for <code>also { }</code> is </p>
  
  <blockquote>
    <p>also - use it when you want to use apply, but don't want to shadow
    this</p>
    
    <p>class FruitBasket {
        private var weight = 0</p>
  
  <pre><code>fun addFrom(appleTree: AppleTree) {
      val apple = appleTree.pick().also { apple -&gt;
          this.weight += apple.weight
          add(apple)
      }
      ...
  }
  ...
  fun add(fruit: Fruit) = ... }
  </code></pre>
    
    <p>Using apply here would shadow this, so that this.weight would refer to
    the apple, and not to the fruit basket.</p>
  </blockquote>
  
  <p>That's also the usage I see quite often. But if I have a look into the documentation at <a href="https://kotlinlang.org/docs/reference/scope-functions.html#also" rel="nofollow noreferrer">kotlinlang.org</a>, they are clearly saying:</p>
  
  <blockquote>
    <p><code>also</code> is good for performing some actions that take the context object
    as an argument. Use also for additional actions that don't alter the
    object, such as logging or printing debug information. Usually, you
    can remove the calls of also from the call chain without breaking the
    program logic.</p>
  </blockquote>
  
  <p>From that point of view, the given example would be wrong as it would break the program logic if it is removed. For me, <code>also</code> is kind of Javas <code>peek</code> (<a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#peek-java.util.function.Consumer-" rel="nofollow noreferrer">doc</a>), which is there, but should not be used for productive program logic.</p>
  
  <p>Can someone enlighten me?</p>