Add a zip_with function.

This commit is contained in:
2020-12-06 20:51:20 -08:00
parent 15f578525d
commit cfd4d1447a
2 changed files with 37 additions and 0 deletions

View File

@@ -1,4 +1,12 @@
class Array(T)
def zip_with(other : Array(R), &block : T, R -> U) forall R, U
dest = [] of U
zip(other) do |l, r|
dest << yield l, r
end
dest
end
def union
reduce(T.new) do |l, r|
l | r