Class: Roast::SystemCogs::Repeat::Output

Inherits:
Cog::Output show all
Defined in:
lib/roast/system_cogs/repeat.rb

Overview

Output from running the repeat cog

Contains results from all iterations that ran. Provides access to the final value (output from the last iteration) as well as individual iteration results.

See Also

  • Roast::CogInputContext#collect - retrieves all iteration outputs as an array (via results)
  • Roast::CogInputContext#reduce - reduces iteration outputs to a single value (via results)

Instance Method Summary collapse

Constructor Details

#initialize(execution_managers) ⇒ Output

Initialize the output with results for all iterations

: (Array) -> void



99
100
101
102
# File 'lib/roast/system_cogs/repeat.rb', line 99

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

Instance Method Details

#firstObject

Get the output from the first iteration

Convenience method equivalent to iteration(0).

See Also

  • iteration
  • last

: () -> Call::Output



158
159
160
# File 'lib/roast/system_cogs/repeat.rb', line 158

def first
  iteration(0)
end

#iteration(index) ⇒ Object

Get the output from a specific iteration

Returns a Roast::SystemCogs::Call::Output object for the iteration at the given index. Supports negative indices to count from the end (e.g., -1 for the last iteration).

Usage

# Access a specific iteration
result = from(repeat!(:process).iteration(2))

# Access with negative index
result = from(repeat!(:process).iteration(-1))

See Also

  • first
  • last
  • value
  • Roast::CogInputContext#from

: (Integer) -> Call::Output



145
146
147
# File 'lib/roast/system_cogs/repeat.rb', line 145

def iteration(index)
  Call::Output.new(@execution_managers.fetch(index))
end

#lastObject

Get the output from the last iteration

Convenience method equivalent to iteration(-1). Returns the same value as calling value, but wrapped in a Roast::SystemCogs::Call::Output for use with from.

See Also

  • iteration
  • first
  • value

: () -> Call::Output



173
174
175
# File 'lib/roast/system_cogs/repeat.rb', line 173

def last
  iteration(-1)
end

#resultsObject

Get all iteration results as a Roast::SystemCogs::Map::Output object

Returns a Roast::SystemCogs::Map::Output containing all iterations, which can be used with collect or reduce to process all iteration outputs.

Usage

# Collect all iteration outputs
all_results = collect(repeat!(:process).results)

# Reduce all iteration outputs
sum = reduce(repeat!(:process).results, 0) { |acc, output| acc + output }

See Also

  • value
  • Roast::CogInputContext#collect
  • Roast::CogInputContext#reduce
  • Roast::SystemCogs::Map::Output

: () -> Map::Output



198
199
200
# File 'lib/roast/system_cogs/repeat.rb', line 198

def results
  Map::Output.new(@execution_managers)
end

#valueObject

Get the final output value from the last iteration

This is the output from the last iteration before break! was called. Returns nil if no iterations ran.

Usage

# Get the final result directly
final = repeat!(:process)

See Also

  • last
  • results

: () -> untyped



120
121
122
# File 'lib/roast/system_cogs/repeat.rb', line 120

def value
  @execution_managers.last&.final_output
end