Jump to content

Category talk:Wren-set: Difference between revisions

(→‎Source code: Added a Bag class plus couple other minor changes.)
(→‎Source code: Bug fix.)
Line 282:
}
 
// Merges all the elements of another Bag or Set object into the current instance
// increasing values where necessary. A specialized version of 'addAll'.
merge(other) {
if (other.type != Bag && other.type != Set) {
Fiber.abort("Argument must be a Bag or a Set.")
}
for (e in other.distinct) _m[e] = _m.containsKey(e) ? _m[e] + other[e] : other[e]
}
 
// Removes an element 'e' from the current instance, if it exists and whether distinct
Line 374:
}
 
// Copies all elements of this instance and another Bag or Set to a new Bag object.
union(other) {
if (other.type != Bag && other.type != Set) {
Fiber.abort("Argument must be a Bag or a Set.")
}
var b = Bag.new()
Line 385:
}
 
// Copies all elements which this instance and another Bag or Set have in common
// to a new Bag object.
intersect(other) {
if (other.type != Bag && other.type != Set) {
Fiber.abort("Argument must be a Bag or a Set.")
}
var b = Bag.new()
Line 403:
}
 
// Copies all elements of this instance which are not elements of another Bag nor Set
// to a new Bag object.
except(other) {
if (other.type != Bag && other.type != Set) {
Fiber.abort("Argument must be a Bag or a Set.")
}
var b = Bag.new()
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.