Class: Roast::SystemCogs::Map::Output

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

Overview

Output from running the map cog

Contains results from each iteration, allowing access to individual iteration outputs. Iterations that did not run (due to break!) will be nil.

See Also

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

Instance Method Summary collapse

Constructor Details

#initialize(execution_managers) ⇒ Output

Initialize the output with results for each iteration

: (Array) -> void



175
176
177
178
# File 'lib/roast/system_cogs/map.rb', line 175

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). Raises MapIterationDidNotRunError if the first iteration did not run.

See Also

  • iteration
  • last

: () -> Call::Output



235
236
237
# File 'lib/roast/system_cogs/map.rb', line 235

def first
  iteration(0)
end

#iteration(index) ⇒ Object

Get the output from a specific iteration, in concert with from

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). Raises MapIterationDidNotRunError if the iteration did not run.

Use from on the return value of this method, as for a single call cog invocation, to access the final output and individual cog outputs from the specified invocation.

Usage

# Access a specific iteration
result = from(map!(:process_items).iteration(2))

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

See Also

  • iteration?
  • first
  • last
  • Roast::CogInputContext#from

: (Integer) -> Call::Output



218
219
220
221
222
223
# File 'lib/roast/system_cogs/map.rb', line 218

def iteration(index)
  em = @execution_managers.fetch(index)
  raise MapIterationDidNotRunError, index unless em.present?

  Call::Output.new(em)
end

#iteration?(index) ⇒ Boolean

Check if a specific iteration ran successfully

Returns true if the iteration at the given index executed, false if it was skipped (e.g., due to break!). Supports negative indices to count from the end.

See Also

  • iteration

: (Integer) -> bool

Returns:

  • (Boolean)


189
190
191
# File 'lib/roast/system_cogs/map.rb', line 189

def iteration?(index)
  @execution_managers.fetch(index).present?
end

#lastObject

Get the output from the last iteration that ran

Convenience method equivalent to iteration(-1). Raises MapIterationDidNotRunError if the last iteration did not run.

See Also

  • iteration
  • first

: () -> Call::Output



249
250
251
# File 'lib/roast/system_cogs/map.rb', line 249

def last
  iteration(-1)
end