Category talk:Wren-set: Difference between revisions
m
→Source code: Now uses Wren S/H lexer.
(→Source code: Added sameDistinct and allDistinct methods to Bag class.) |
m (→Source code: Now uses Wren S/H lexer.) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1:
===Source code===
<syntaxhighlight lang="
/* Set represents an unordered collection of unique objects. It is implemented as a Map
Line 104:
for (k in _m.keys) m[k] = 1
return m
}
// Copies the elements of the current instance to a Bag, with a value of 1, and
// returns the Bag.
toBag {
var b = Bag.new()
for (k in _m.keys) b.add(k, 1)
return b
}
Line 235 ⟶ 243:
isEmpty { _m.count == 0 }
//
distinct { _m.keys }▼
values { _m.values }
// Adds an element 'e' to the current instance. If the bag already contains 'e'
// its value is incremented.
add(e) {
Line 344 ⟶ 358:
// Returns whether or not the current instance contains no elements of a sequence.
containsNone(seq) { !containsAny(seq) }
▲ // Returns a sequence of all distinct elements in the current instance.
▲ distinct { _m.keys }
// Copies the elements of the current instance to a List and returns the List.
// An element with value 'v' is repeated 'v' times.
var l = []
for (k in _m.keys) {
Line 366 ⟶ 377:
return m
}
// Copies the distinct elements of the current instance to a Set and
// returns the set
toSet { Set.new(distinct) }
// Copies the elements of the current instance to a new Bag object.
|