alsoapply のようなスコープ関数内にある forEach 関数で、単純化できるものを報告します。

forEach の呼び出しを onEach に変換」クイックフィックスを使用すると、コードを自動的に修正できます。

例:


  fun test(list: List<Int>) {
      val x = list.also { it.forEach { it + 4 } }.toString()
      val y = list.apply { forEach { println(it) } }
  }

クイックフィックス適用後:


  fun test(list: List<Int>) {
      val x = list.onEach { it + 4 }.toString()
      val y = list.onEach { println(it) }
  }