Values & References13 / 16
Up next

Pass a mutable reference

import scala.collection.mutable.ArrayBuffer

// the parameter shares the caller's buffer
def addOne(buf: ArrayBuffer[Int]): Unit =
  buf += 1

@main def main(): Unit =
  val data = ArrayBuffer(10, 20)
  addOne(data)
  println(data)
What you're solving

the callee mutates the caller's data