Category talk:Wren-llist: Difference between revisions
Content added Content deleted
m (→Source code: Minor change to exchange() methods.) |
(→Source code: 'add' methods now return the item(s) added.) |
||
Line 87: | Line 87: | ||
isEmpty { _count == 0 } |
isEmpty { _count == 0 } |
||
// Adds an element at the tail of the current instance. |
// Adds an element at the tail of the current instance and returns it. |
||
add(d) { |
add(d) { |
||
var node = Node.new(d) |
var node = Node.new(d) |
||
Line 101: | Line 101: | ||
} |
} |
||
_tail = node |
_tail = node |
||
return d |
|||
} |
} |
||
// Adds a sequence of elements at the tail of the current instance. |
// Adds a sequence of elements at the tail of the current instance and returns them. |
||
addAll(a) { |
addAll(a) { |
||
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
||
for (e in a) add(e) |
for (e in a) add(e) |
||
return a |
|||
} |
} |
||
// Inserts an element at the head of the current instance. |
// Inserts an element at the head of the current instance and returns it. |
||
prepend(d) { insert_(0, d) } |
prepend(d) { insert_(0, d) } |
||
// Inserts a sequence of elements at the head of the current instance. |
// Inserts a sequence of elements at the head of the current instance and returns them. |
||
prependAll(a) { |
prependAll(a) { |
||
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
||
Line 120: | Line 122: | ||
i = i + 1 |
i = i + 1 |
||
} |
} |
||
return a |
|||
} |
} |
||
Line 527: | Line 530: | ||
isEmpty { _count == 0 } |
isEmpty { _count == 0 } |
||
// Adds an element at the tail of the current instance. |
// Adds an element at the tail of the current instance and returns it. |
||
add(d) { |
add(d) { |
||
var node = DNode.new(d) |
var node = DNode.new(d) |
||
Line 543: | Line 546: | ||
} |
} |
||
_tail = node |
_tail = node |
||
return d |
|||
} |
} |
||
// Adds a sequence of elements at the tail of the current instance. |
// Adds a sequence of elements at the tail of the current instance and returns them. |
||
addAll(a) { |
addAll(a) { |
||
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
||
for (e in a) add(e) |
for (e in a) add(e) |
||
return a |
|||
} |
} |
||
// Inserts an element at the head of the current instance. |
// Inserts an element at the head of the current instance and returns it. |
||
prepend(d) { insert_(0, d) } |
prepend(d) { insert_(0, d) } |
||
// Inserts a sequence of elements at the head of the current instance. |
// Inserts a sequence of elements at the head of the current instance and returns them. |
||
prependAll(a) { |
prependAll(a) { |
||
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
if (!(a is Sequence)) Fiber.abort("Argument must be a Sequence.") |
||
Line 562: | Line 567: | ||
i = i + 1 |
i = i + 1 |
||
} |
} |
||
return a |
|||
} |
} |
||