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="ecmascriptwren">/* Module "set.wren" */
 
/* 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 }
 
// AddsReturns ana elementsequence 'e'of toall distinct elements in the current instance. If the set already contains 'e'
distinct { _m.keys }
 
// Returns a sequence of all distinct elementsvalues in the current instance.
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.
toListtoFlatList {
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.
9,483

edits