All Downloads are FREE. Search and download functionalities are using the official Maven repository.

japgolly.microlibs.utils.SetOnceVar.scala Maven / Gradle / Ivy

The newest version!
package japgolly.microlibs.utils

final class SetOnceVar[A] {
  private var instance = Option.empty[A]

  def getOrSet(value: => A): A =
    synchronized {
      if (instance.isDefined)
        instance.get
      else {
        val a = value
        instance = Some(a)
        a
      }
    }
}

object SetOnceVar {
  def apply[A]: SetOnceVar[A] =
    new SetOnceVar
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy