Class: Hegel::Generators::TupleGenerator

Inherits:
Hegel::Generator show all
Defined in:
lib/hegel/generators.rb,
sig/hegel.rbs

Overview

Hegel::Syntax::Methods#tuples. Draws each of generators in order into an Array (Ruby has no tuple type; see docs/adr/0004). The label table assigns tuples a single span around the whole draw, unlike arrays/sets/hashes: each position is a distinct generator already, not repeated draws of one, so there is no per-element span to open.

Instance Method Summary collapse

Methods inherited from Hegel::Generator

#filter, #map

Constructor Details

#initialize(generators) ⇒ TupleGenerator

Returns a new instance of TupleGenerator.

Parameters:



272
273
274
275
# File 'lib/hegel/generators.rb', line 272

def initialize(generators)
  super()
  @generators = generators
end

Instance Method Details

#do_draw(tc) ⇒ Array[untyped]

Parameters:

  • tc (Object)

Returns:

  • (Array[untyped])


277
278
279
280
281
282
283
284
# File 'lib/hegel/generators.rb', line 277

def do_draw(tc)
  tc.start_span(LibHegel::HEGEL_LABEL_TUPLE)
  begin
    @generators.map { |generator| generator.do_draw(tc) }
  ensure
    tc.stop_span(discard: false)
  end
end