Module: FunctionalLightService::Sequencer

Included in:
Prelude
Defined in:
lib/functional-light-service/functional/sequencer.rb

Overview

Do-notation for Result: chains steps that return Success/Failure, short-circuiting on the first Failure. Ported from the deterministic gem (MIT License, Copyright (c) Piotr Zolnierek and contributors, https://github.com/pzol/deterministic).

in_sequence do
get(:user)  { fetch_user(id) }      # binds the Success value to :user
let(:name)  { user.fetch(:name) }   # binds a plain (non-Result) value
and_then    { validate(user) }      # step without binding
observe     { log(name) }           # side effect, return value ignored
and_yield   { Success(name) }       # final result of the sequence
end

Defined Under Namespace

Modules: Operation Classes: InvalidSequenceError, OperationWrapper, Sequencer

Instance Method Summary collapse

Instance Method Details

#in_sequenceObject



29
30
31
32
33
# File 'lib/functional-light-service/functional/sequencer.rb', line 29

def in_sequence(&)
  sequencer = Sequencer.new(self)
  sequencer.instance_eval(&)
  sequencer.yield
end