Category talk:Wren-seq: Difference between revisions

m
→‎Source code: Now uses Wren S/H lexer.
(→‎Source code: Added Lst.expand method.)
m (→‎Source code: Now uses Wren S/H lexer.)
 
(4 intermediate revisions by the same user not shown)
Line 1:
===Source code===
 
<syntaxhighlight lang="ecmascriptwren">/* Module "seq.wren" */
 
import "./trait" for Cloneable, CloneableSeq
Line 18:
return true
}
 
// Returns true if any adjacent elements of the sequence are duplicates, false otherwise.
static hasAdjDup(s) {
isSeq_(s)
var iter = s.iterate(null)
if (!iter) return false
var prev = s.iteratorValue(iter)
while (iter = s.iterate(iter)) {
var next = s.iteratorValue(iter)
if (next == prev) return true
prev = next
}
return false
}
 
// Returns a new 'lazy' sequence that iterates only the last 'count' elements of
// the original sequence.
Line 201 ⟶ 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'
Line 799 ⟶ 835:
// As 'multiples' but where 'first' and 'multiplier' are the same.
static powers(first, n) { multiples(first, n, first) }
 
// Builds and returns a list of corresponding columns from a non-empty list 'a'
// of rows, where each row is a non-empty list of any element type. The number
// of columns in each row must be the same.
static columns(a) {
var nr = a.count
if (nr == 0) Fiber.abort("List must contain at least one row.")
var nc = a[0].count
if (nc == 0) Fiber.abort("Rows must have at least one column.")
if (a.skip(1).any { |e| e.count != nc }) {
Fiber.abort("Rows must all have the same number of columns.")
}
var cols = List.filled(nc, null)
for (j in 0...nc) {
cols[j] = List.filled(nr, 0)
for (i in 0...nr) cols[j][i] = a[i][j]
}
return cols
}
}
 
Line 864 ⟶ 919:
pop() {
var item = peek()
if (!(item !=is nullNull)) {
_stack.removeAt(-1)
}
9,476

edits