Add some utility methods for lists of sets.
This commit is contained in:
parent
48ba4e1577
commit
15f578525d
13
src/advent/util.cr
Normal file
13
src/advent/util.cr
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
class Array(T)
|
||||||
|
def union
|
||||||
|
reduce(T.new) do |l, r|
|
||||||
|
l | r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def intersect
|
||||||
|
reduce do |l, r|
|
||||||
|
l & r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user