Category talk:Wren-seq: Difference between revisions

Content added Content deleted
(→‎Source code: Added Lst.exchange method.)
(→‎Source code: Some fairly minor adjustments to the Stack class.)
Line 67: Line 67:
var count = a.count
var count = a.count
var indices = []
var indices = []
if (count == 0) return [false, 0, indices]
if (count == 0) return [false, 0, indices]
if (start < 0) start = count + start
if (start < 0) start = count + start
for (i in start...count) {
for (i in start...count) {
Line 385: Line 385:
// Returns the number of elements in the stack.
// Returns the number of elements in the stack.
count { _stack.count }
count { _stack.count }

// Returns whether or not the stack is empty.
isEmpty { count == 0 }


// Removes all elements from the stack.
// Removes all elements from the stack.
Line 390: Line 393:


// Returns the last item on the stack without removing it.
// Returns the last item on the stack without removing it.
// Returns null if the stack is empty.
peek() { (!isEmpty) ? _stack[-1] : null }
peek() { (!isEmpty) ? _stack[-1] : null }


Line 395: Line 399:
push(item) { _stack.add(item) }
push(item) { _stack.add(item) }


// Adds 'items' (in order) to the stack and returns them.
// Adds a sequence of 'items' (in order) to the stack and returns them.
pushAll(items) { _stack.addAll(items) }
pushAll(items) { _stack.addAll(items) }


// Removes the last item from the stack and returns it.
// Removes the last item from the stack and returns it.
// Returns null if the stack is empty.
pop() {
pop() {
var item = peek()
var item = peek()
Line 409: Line 414:
// Clones the stack.
// Clones the stack.
clone() {
clone() {
var n = Stack.new()
var s = Stack.new()
n.pushAll(Lst.clone(_stack))
s.pushAll(Lst.clone(_stack))
return n
return s
}
}