Class: RFunk::Lazy

Inherits:
Object
  • Object
show all
Defined in:
lib/rfunk/lazy.rb

Instance Method Summary collapse

Constructor Details

#initialize(lambda) ⇒ Lazy

Returns a new instance of Lazy.


3
4
5
6
7
# File 'lib/rfunk/lazy.rb', line 3

def initialize(lambda)
  @lambda = lambda
  @created = false
  @atomic = Concurrent::AtomicReference.new
end

Instance Method Details

#created?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/rfunk/lazy.rb', line 14

def created?
  created
end

#valueObject


9
10
11
12
# File 'lib/rfunk/lazy.rb', line 9

def value
  atomic.update { @value ||= lambda.call.tap { self.created = true } }
  RFunk.option(atomic.value)
end