Skip to content

Instantly share code, notes, and snippets.

View mairbek's full-sized avatar
🎩
¯\_(ツ)_/¯

Mairbek Khadikov mairbek

🎩
¯\_(ツ)_/¯
View GitHub Profile
class WriteOnce[T] {
private val ref = new java.util.concurrent.atomic.AtomicReference[Option[T]](None)
def init(t: T) { if(!ref.compareAndSet(None, Some(t))) sys.error("Already written"); }
def get: Option[T] = ref.get
}
scala> val w = new WriteOnce[Int]
w: WriteOnce[Int] = WriteOnce@215d55cb
scala> w.get