2
我想用Elixir來映射陣列(n個陣列)的每個正方形。Elixir陣列的深度圖
使用Ruby,這可能是與此一堆代碼來完成:
class Object
def deep_map(&block)
block.call(self)
end
end
class Array
def deep_map(&block)
map {|e| e.deep_map(&block) }
end
end
然後,
[
[
[nil, "foo"],
[nil, nil]
],
[
[nil, "bar"],
[nil, "baz"]
]
].deep_map {|el| el.to_s * 2 }
我們怎麼可以做同樣的靈藥?感謝您的燈光!
太棒了,謝謝@legoscia!完美地工作! – Doug