Class: Hegel::Stateful::Pool::ValuesReusable

Inherits:
Generator
  • Object
show all
Defined in:
lib/hegel/stateful/pool.rb,
sig/hegel.rbs

Overview

Hegel::Generator returned by Pool#values_reusable. Left un-namespaced under Hegel::Generators, the same way Hegel::Generator::Mapped and ::Filtered are: reached only through Pool#values_reusable, not part of this library's own public generator vocabulary.

Instance Method Summary collapse

Methods inherited from Generator

#filter, #map

Constructor Details

#initialize(pool, values) ⇒ ValuesReusable

Returns a new instance of ValuesReusable.

Parameters:

  • pool (Object)
  • values (Hash[Integer, untyped])


73
74
75
76
77
# File 'lib/hegel/stateful/pool.rb', line 73

def initialize(pool, values)
  super()
  @pool = pool
  @values = values
end

Instance Method Details

#do_draw(tc) ⇒ Object

Does not check @values.empty? before drawing: hegel_pool_generate already answers HEGEL_E_ASSUME for an empty pool, which Hegel::LibHegel.check! already translates to Hegel::AssumeFailed -- the same translation every other assumption failure gets. hegel-rust's own ValuesReusable calls tc.assume ahead of its own pool_generate call (src/stateful.rs). Here the engine's answer is the single path, so the empty case has one place to change.

Parameters:

  • tc (Object)

Returns:

  • (Object)


86
87
88
89
# File 'lib/hegel/stateful/pool.rb', line 86

def do_draw(tc)
  variable_id = tc.pool_generate(@pool, false)
  @values.fetch(variable_id)
end