Module: Fairy::SegMap::Interface

Defined in:
lib/fairy/client/seg-map.rb

Instance Method Summary collapse

Instance Method Details

#emap(block_source, opts = nil) ⇒ Object

emap(%{|input| input.collect{..})



30
31
32
33
34
# File 'lib/fairy/client/seg-map.rb', line 30

def emap(block_source, opts = nil)
	ERR::Raise ERR::CantAcceptBlock if block_given?
	map_source = %{|i, block| proc{#{block_source}}.call(i).each{|e| block.call e}}
	seg_map(map_source, opts)
end

#map_flatten(block_source, opts = nil) ⇒ Object Also known as: mapf



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fairy/client/seg-map.rb', line 36

def map_flatten(block_source, opts = nil)
	ERR::Raise ERR::CantAcceptBlock if block_given?
	map_source = %{|i, block|
    i.each do |e|
      enum = proc{#{block_source}}.call(e)
      enum.each do |f|
        #{n = opts && opts[:N]; n ||= 1
          case n
          when 1
            "block.call f"
          when 2
            "if f.respond_to?(:each)
               f.each{|g| block.call(g)}
             else
               block.call f
             end"
          else
           "if f.respond_to?(:flatten)
              f.flatten(#{opts[:N]} - 2).each{|g| block.call(g)}
            else
              block.call f
            end"
          end}
      end
    end
  }
	seg_map(map_source, opts)
end

#seg_map(block_source, opts = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/fairy/client/seg-map.rb', line 21

def seg_map(block_source, opts = nil)
	ERR::Raise ERR::CantAcceptBlock if block_given?
	block_source = BlockSource.new(block_source) 
	mapper = SegMap.new(@fairy, opts, block_source)
	mapper.input=self
	mapper
end

#smap(block_source, opts = nil) ⇒ Object



13
14
15
# File 'lib/fairy/client/seg-map.rb', line 13

def smap(block_source, opts = nil)
	raise "No compatibility after fairy-0.5"
end

#smap2(block_source, opts = nil) ⇒ Object



17
18
19
# File 'lib/fairy/client/seg-map.rb', line 17

def smap2(block_source, opts = nil)
	raise "No compatibility after fairy-0.6"
end