Category talk:Wren-seq: Difference between revisions

→‎Source code: Added Lst.reverse and Lst.removeBy, removed Lst.toMap (going to new MapUtil module).
(→‎Source code: Added Lst.lshift/rshift methods and made some existing methods 'chaining' friendly.)
(→‎Source code: Added Lst.reverse and Lst.removeBy, removed Lst.toMap (going to new MapUtil module).)
Line 493:
if (final > 0) res.add(a[first..-1])
return res
}
 
// Reverses a list in place and returns it.
static toMapreverse(k, va) {
isList_(ka)
var mc = {}a.count
if (c < 2) return ma
isList_(v)var i = 0
forvar (ij in= 0...ka.count) m[k[i]] =- v[i]1
while (i < j) {
a.swap(i, j)
i = i + 1
j = j - 1
}
return a
}
 
Line 517 ⟶ 532:
}
return found ? value : null
}
 
// Removes all elements from 'a' which satisfy the predicate
// function 'fn' and returns a list of the elements removed.
static removeBy(a, fn) {
isList_(a)
if (a.isEmpty) return []
var removals = []
for (i in a.count-1..0) {
var e = a[i]
if (fn.call(e)) {
removals.add(a.remove(e))
}
}
return reverse(removals)
}
 
Line 534 ⟶ 564:
// Removes all elements of 'a' from index 'start' to the end and returns it.
static truncate(a, start) { clearPart(a, start, -1) }
 
// 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
}
 
// Returns a clone of 'a' by recursively cloning any elements which are
9,476

edits