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
|