Add drawing code and elementwise reduction.

This commit is contained in:
Danila Fedorin 2020-12-07 18:42:44 -08:00
parent a5e6c4c145
commit 6fc6c5cf53
1 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,12 @@ class Array(T)
dest
end
def reduce_elementwise(&block)
reduce do |l, r|
l.zip_with(r) { |a, b| yield a, b }
end
end
def union
reduce(T.new) do |l, r|
l | r
@ -18,6 +24,15 @@ class Array(T)
l & r
end
end
def draw(width, maps)
self.each_slice(width) do |slice|
slice.each do |c|
print maps[c]
end
puts
end
end
end
struct Tuple(*T)