Class: Quick::Sampler::DSL::Fluidiom
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Quick::Sampler::DSL::Fluidiom
- Includes:
- Config
- Defined in:
- lib/quick/sampler/dsl/fluidiom.rb
Overview
A Quick::Sampler wrapper providing a fluid DSL that can be used in a sampler definition passed to Quick::Sampler.compile.
Instance Method Summary collapse
-
#initialize(sampler, _config = {}) ⇒ Fluidiom
constructor
private
wraps a
samplerinto aFluidiominstance so it has extra methods while inside the block passed to Quick::Sampler.compile. -
#map {|sample| ... } ⇒ Quick::Sampler
spawn a mapping sampler.
-
#spawn(sampler) ⇒ Quick::Sampler
Wrapped sampler that starts out with the same config as this one.
-
#such_that {|sample| ... } ⇒ Quick::Sampler
spawn a filtering sampler.
-
#unwrap ⇒ Quick::Sampler
The unwrapped original sampler.
Methods included from Config
Constructor Details
#initialize(sampler, _config = {}) ⇒ Fluidiom
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
wraps a sampler into a Fluidiom instance so it has extra methods while
inside the block passed to Quick::Sampler.compile
14 15 16 17 18 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 14 def initialize sampler, _config = {} sampler = Base.new(sampler) unless sampler.is_a? Base super(sampler) config.merge! _config end |
Instance Method Details
#map {|sample| ... } ⇒ Quick::Sampler
spawn a mapping sampler
The produced sampler will yield each original sample to the block and return block result instead.
59 60 61 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 59 def map &block spawn(unwrap.map(&block)) end |
#spawn(sampler) ⇒ Quick::Sampler
28 29 30 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 28 def spawn sampler self.class.new(sampler, config) end |
#such_that {|sample| ... } ⇒ Quick::Sampler
spawn a filtering sampler
The produced sampler honors the config variable max_iterations and stops
iterating when that many original values are tested.
44 45 46 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 44 def such_that &predicate spawn(unwrap.take(max_iterations).select(&predicate)) end |
#unwrap ⇒ Quick::Sampler
22 23 24 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 22 def unwrap __getobj__ end |