Category talk:Wren-seq: Difference between revisions
Content added Content deleted
(→Source code: Added Lst.columns method.) |
(Added Lst.resize method.) |
||
Line 216: | Line 216: | ||
static refill2(a, filler) { refill2(a, filler, null) } |
static refill2(a, filler) { refill2(a, filler, null) } |
||
static refill3(a, filler) { refill3(a, filler, null) } |
static refill3(a, filler) { refill3(a, filler, null) } |
||
// Creates a new list of size 'size' and copies all the elements (or the first 'size' elements) |
|||
// of 'a' into it starting from index 0. Any remaining slots are filled by a copy of 'filler'. |
|||
// 'copier' is a function which takes a single argument and returns a copy of that argument. |
|||
static resize(a, size, filler, copier) { |
|||
Lst.isList_(a) |
|||
if (size.type != Num || !size.isInteger || size < 0) { |
|||
Fiber.abort("'size' must be a non-negative integer.") |
|||
} |
|||
var res = List.filled(size, null) |
|||
var rc = a.count.min(size) |
|||
for (i in 0...rc) res[i] = !copier ? a[i] : copier.call(a[i]) |
|||
if (size > a.count) { |
|||
for (i in rc...size) res[i] = !copier ? filler : copier.call(filler) |
|||
} |
|||
return res |
|||
} |
|||
// Overloads of above method where elements/filler are immutable, not needed or null. |
|||
static resize(a, size, filler) { resize (a, size, filler, null) } |
|||
static resize(a, size) { resize (a, size, null, null) } |
|||
// Creates a list and fills it with a series of numbers starting from 'start' |
// Creates a list and fills it with a series of numbers starting from 'start' |