Category talk:Wren-seq: Difference between revisions

Content added Content deleted
(→‎Source code: Added more methods to assist with initialization.)
(→‎Source code: Added 'replaceAll and 'toMap' methods to Lst class.)
Line 443: Line 443:
}
}
return [old, swap]
return [old, swap]
}

// Removes all instances of 'value' from 'a'.
// Returns 'value' if there were any removals, otherwise 'null'.
static removeAll(a, value) {
isList_(a)
if (a.isEmpty) return null
var found = false
for (i in a.count-1..0) {
if (a[i] == value) {
a.removeAt(i)
found = true
}
}
return found ? value : null
}

// Return a map whose keys are 'k' and corresponding values 'v'
// where 'k' and 'v' are suitable lists.
static toMap(k, v) {
isList_(k)
isList_(v)
if (k.count != v.count) Fiber.abort("The number of keys and values must be the same.")
var m = {}
for (i in 0...k.count) m[k[i]] = v[i]
return m
}
}