Sha256: 0bde9b2f58e35bd3c4e62c8ec47e387a4854d15aa02b8b026d315d7e61748519
Contents?: true
Size: 975 Bytes
Versions: 2
Compression:
Stored size: 975 Bytes
Contents
# frozen_string_literal: true class Operation include Dry::Effects.State(:counter) include Dry::Effects.Amb(:feature_enabled) def call if feature_enabled? self.counter += 10 :with_feature else self.counter += 1 :without_feature end end end module Handler include Dry::Effects::Handler.State(:counter, as: :with_counter) include Dry::Effects::Handler.Amb(:feature_enabled, as: :test_feature) end class AmbState include Handler def initialize @operation = Operation.new end def call test_feature { with_counter(0) { @operation.call } } end end class StateAmb include Handler def initialize @operation = Operation.new end def call with_counter(0) { test_feature { @operation.call } } end end amb_then_state = AmbState.new state_then_amb = StateAmb.new amb_then_state.() # => [[1, :without_feature], [10, :with_feature]] state_then_amb.() # => [11, [:without_feature, :with_feature]]
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-effects-0.1.0.alpha2 | examples/amb.rb |
dry-effects-0.1.0.alpha | examples/amb.rb |