Module: TypedOperation::Operations::Composition
- Included in:
- Base, ChainedOperation, ImmutableBase, PartiallyApplied, Pipeline::ChainableWrapper
- Defined in:
- lib/typed_operation/operations/composition.rb
Overview
Provides composition methods for chaining operations together. Included in operation classes and composed operations (ChainedOperation, Pipeline).
Instance Method Summary collapse
-
#or_else(fallback = nil, &block) ⇒ Object
Provides a fallback when the operation fails.
-
#then(operation = nil, **extra_kwargs, &block) ⇒ Object
Smart sequential composition with context accumulation.
-
#then_passes(operation = nil, &block) ⇒ Object
Passes the context as a single positional argument to the next operation.
-
#then_spreads(operation = nil, &block) ⇒ Object
Spreads the context as **kwargs to the next operation.
-
#transform(&block) ⇒ Object
Transforms the success value, replacing the context entirely.
Instance Method Details
#or_else(fallback = nil, &block) ⇒ Object
Provides a fallback when the operation fails. : (?(singleton(Base) | Proc)) ?{ (untyped) -> untyped } -> FallbackChain
36 37 38 |
# File 'lib/typed_operation/operations/composition.rb', line 36 def or_else(fallback = nil, &block) FallbackChain.new(self, fallback || block) end |
#then(operation = nil, **extra_kwargs, &block) ⇒ Object
Smart sequential composition with context accumulation. Auto-detects whether to spread kwargs or pass as single value. : (?(singleton(Base) | Proc), **untyped) ?{ (untyped) -> untyped } -> SmartChain
12 13 14 |
# File 'lib/typed_operation/operations/composition.rb', line 12 def then(operation = nil, **extra_kwargs, &block) SmartChain.new(self, operation || block, extra_kwargs) end |
#then_passes(operation = nil, &block) ⇒ Object
Passes the context as a single positional argument to the next operation. : (?(singleton(Base) | Proc)) ?{ (untyped) -> untyped } -> SequenceChain
24 25 26 |
# File 'lib/typed_operation/operations/composition.rb', line 24 def then_passes(operation = nil, &block) SequenceChain.new(self, operation || block) end |
#then_spreads(operation = nil, &block) ⇒ Object
Spreads the context as **kwargs to the next operation. : (?(singleton(Base) | Proc)) ?{ (untyped) -> untyped } -> SplatChain
18 19 20 |
# File 'lib/typed_operation/operations/composition.rb', line 18 def then_spreads(operation = nil, &block) SplatChain.new(self, operation || block) end |