Class: Quick::Sampler::DSL::Fluidiom
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Quick::Sampler::DSL::Fluidiom
- 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) ⇒ 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
A new fluidiom-wrapped sampler.
-
#such_that(max_iterations: 1000) {|sample| ... } ⇒ Quick::Sampler
spawn a filtering sampler.
-
#unwrap ⇒ Quick::Sampler
The unwrapped original sampler.
Constructor Details
#initialize(sampler) ⇒ 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
13 14 15 16 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 13 def initialize sampler sampler = Base.new(sampler) unless sampler.is_a? Base super(sampler) 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.
56 57 58 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 56 def map &block spawn(unwrap.map(&block)) end |
#spawn(sampler) ⇒ Quick::Sampler
Returns a new fluidiom-wrapped sampler.
26 27 28 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 26 def spawn sampler self.class.new(sampler) end |
#such_that(max_iterations: 1000) {|sample| ... } ⇒ Quick::Sampler
spawn a filtering sampler
41 42 43 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 41 def such_that max_iterations: 1000, &predicate spawn(unwrap.take(max_iterations).select(&predicate)) end |
#unwrap ⇒ Quick::Sampler
Returns the unwrapped original sampler.
20 21 22 |
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 20 def unwrap __getobj__ end |