Class: TypedOperation::SequenceChain

Inherits:
ChainedOperation show all
Includes:
Result::Mixin
Defined in:
lib/typed_operation/chains/sequence_chain.rb

Overview

Sequential composition chain used by .then_passes Passes the success value (context) to the right operation/block. The result is merged back into context. Short-circuits on failure.

Instance Method Summary collapse

Methods inherited from ChainedOperation

#initialize

Methods included from Operations::Composition

#or_else, #then, #then_passes, #then_spreads, #transform

Constructor Details

This class inherits a constructor from TypedOperation::ChainedOperation

Instance Method Details

#callObject

: (*untyped, **untyped) -> _Result[untyped, untyped]



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/typed_operation/chains/sequence_chain.rb', line 13

def call(...)
  result = @left.call(...)
  return result if result.failure?

  left_value = result.value!
  context = to_context(left_value)

  right_result = @right.call(context)
  return right_result if right_result.failure?

  # Merge right's output into context
  right_value = right_result.value!
  merged = merge_into_context(context, right_value)

  Success(merged)
end