Category talk:Wren-seq: Difference between revisions

m
→‎Source code: Now uses Wren S/H lexer.
(→‎Source code: Added Lst.columns method.)
m (→‎Source code: Now uses Wren S/H lexer.)
 
(One intermediate revision by the same user not shown)
Line 1:
===Source code===
 
<syntaxhighlight lang="ecmascriptwren">/* Module "seq.wren" */
 
import "./trait" for Cloneable, CloneableSeq
Line 216:
static refill2(a, filler) { refill2(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'
9,476

edits