Class: Quick::Sampler::DSL::Fluidiom

Inherits:
SimpleDelegator
  • Object
show all
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

Methods included from Config

#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.

Yield Parameters:

  • sample (Anything)

    the original sample

Yield Returns:

  • (Anything)

    the mapped sample to return



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.

Yield Parameters:

  • sample (Anything)

    a sampled value to be tested

Yield Returns:

  • (Boolean)

    true to pass the value through



44
45
46
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 44

def such_that &predicate
  spawn(unwrap.take(max_iterations).select(&predicate))
end

#unwrapQuick::Sampler



22
23
24
# File 'lib/quick/sampler/dsl/fluidiom.rb', line 22

def unwrap
  __getobj__
end