Bag
Bag('foo', 'bar', 'baz')Operations
var A = Bag('foo', 'bar', 'baz', 'foo')
var B = Bag('bar', 'foo', 'qux')
# Count how many times is 'foo' present in the bag A
say A.count('foo') #=> 2
# Intersection
say (A & B) #=> Bag("foo", "bar")
# Union
say (A | B) #=> Bag("qux", "bar", "baz", "foo", "foo")
# Difference
say (A - B) #=> Bag("baz", "foo")
say (B - A) #=> Bag("qux")
# Symmetric difference
say (A ^ B) #=> Bag("foo", "qux", "baz")
# Concatenation
say (A + B) #=> Bag("foo", "foo", "foo", "bar", "bar", "baz", "qux")Updating the bag
Last updated