package ocelot.desktop.util

class Lazy[A](init: () => A) {
  private var _value = Option.empty[A]

  def get: A = _value match {
    case Some(value) => value

    case None =>
      val v = init()
      _value = Some(v)

      v
  }

  def getSync: A = synchronized(get)

  def getOption: Option[A] = _value
}

object Lazy {
  def apply[A](init: => A): Lazy[A] = new Lazy(() => init)
}
