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.
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) }
▲ static toMap(k, v) {
▲ isList_(k)
▲ isList_(v)
▲ 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
|