| kind | = | "List" |
A list is a collection of objects that can change size
- *(sepOrRep)
- +(otherList)
- -(otherList)
- <<(value)
- <=>(other)
- ==(other)
- ===(other)
- ?&(...)
- ?|(...)
- [](...)
- []=(...)
- append!(value)
- asList()
- assoc(obj)
- at(index)
- at=(index, value)
- butLast(n 1)
- choose(quantity nil)
- clear!()
- collect!(...)
- compact()
- compact!()
- concat!(otherList)
- each([indexOrArgOrCode] nil, [argOrCode] nil, [code] nil)
- empty?()
- flatten()
- flatten!()
- hash()
- ifEmpty(...)
- include?(object)
- index(obj)
- insert!(index, +objects)
- inspect()
- join(separator )
- last()
- length(...)
- map!([argOrCode], [code] nil)
- notice()
- pick(quantity nil)
- pick!(quantity nil)
- pop!()
- prepend!(value)
- push!(...)
- random()
- randomIndex()
- rassoc(obj)
- remove!(element, +elements)
- removeAt!(indexOrRange)
- removeFirst!(element, +elements)
- removeIf!([argOrCode], [code] nil)
- rest()
- reverse()
- reverse!()
- rindex(obj)
- second()
- seq()
- shift!()
- shuffle()
- shuffle!()
- size()
- sort()
- sort!()
- third()
- unshift!(...)
- - should return nil for an empty list
[ show source ]
[] first should be nil
- - should return the first element for a non-empty list
[ show source ]
[](42) first should ==(42)
takes either a text or a number. if given a text, it works like join, while if it gets a number, it will return a new list repeated as many times as the number argument
[ show source ]
method(sepOrRep,
if(sepOrRep mimics?(Text),
self join(sepOrRep),
result = list
sepOrRep times(result concat!(self))
result))
- - is equivalent to self join(text) when passed a Text
[ show source ]
([](1, 2, 3) *(",")) should ==([](1, 2, 3) join(",")) - - concatenates n copies of the list when passed an integer
[ show source ]
([](1, 2, 3) *(0)) should ==([]) ([](1, 2, 3) *(1)) should ==([](1, 2, 3)) ([](1, 2, 3) *(3)) should ==([](1, 2, 3, 1, 2, 3, 1, 2, 3)) ([] *(10)) should ==([])
returns a new list that contains the receivers elements and the elements of the list sent in as the argument.
- - should return the same list when applied to an empty list
[ show source ]
x = [](1, 2, 3) (x +([])) should ==(x) x = [](1, 2, 3) ([] +(x)) should ==(x)
- - should add two lists together, preserving the order
[ show source ]
x = [](1, 2, 3) (x +([](4, 5, 6))) should ==([](1, 2, 3, 4, 5, 6)) x = [](1, 2, 3) ([](4, 5, 6) +(x)) should ==([](4, 5, 6, 1, 2, 3))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:("+"), []) - - should validate type of argument
[ show source ]
fn([](1, 2, 3) +(3)) should signal(Condition Error Type IncorrectType)
returns a new list that contains all the elements from the receivers list, except for those that are in the argument list
- - should return the same list when given an empty list
[ show source ]
x = [](1, 2, 3) (x -([])) should ==(x)
- - should return an empty list when subtracting from an empty list
[ show source ]
x = [](1, 2, 3) ([] -(x)) should ==([])
- - should remove all elements that are the same from the first list
[ show source ]
x = [](1, 2, 3) y = [](2, 4, 6, 2) (x -(y)) should ==([](1, 3)) (y -(x)) should ==([](4, 6))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:("-"), []) - - should validate type of argument
[ show source ]
fn([](1, 2, 3) -(3)) should signal(Condition Error Type IncorrectType)
takes one argument and adds it at the end of the list, and then returns the list
- - should add the element at the end of an empty list
[ show source ]
x = [] x <<(42) x length should ==(1) x [](0) should ==(42)
- - should add the element at the end of a list with elements
[ show source ]
x = [](1, 2, 3) x <<(42) x length should ==(4) x [](0) should ==(1) x [](1) should ==(2) x [](2) should ==(3) x [](3) should ==(42)
- - should return the list after the append
[ show source ]
x = [] (x <<(42)) should ==(x)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:("<<"), 1)
Compares this object against the argument. The comparison is only based on the elements inside the lists, which are in turn compared using <=>.
- - should sort based on the elements inside
[ show source ]
([] <=>([])) should ==(0) ([] <=>([](1))) should ==(-(1)) ([](1) <=>([])) should ==(1) ([](1) <=>([](1))) should ==(0) ([](1, 2) <=>([](1))) should ==(1) ([](1) <=>([](1, 2))) should ==(-(1)) ([](1, 2) <=>([](1, 3))) should ==(-(1)) ([](1, 3) <=>([](1, 2))) should ==(1)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:("<=>"), [])
returns true if the left hand side list is equal to the right hand side list.
- - should return false when sent an argument that is not a list
[ show source ]
[] should not ==(1) [](1) should not ==(1) [](1, 2, 3) should not ==("foo") [] should not ==(fn([])) - - should return true for two empty lists
[ show source ]
x = [] x should ==(x) [] should ==([])
- - should return true for two empty lists where one has a new cell
[ show source ]
x = [] y = [] x blarg = 12 x should ==(y)
- - should return false when the two lists have an element of different types
[ show source ]
[](1) should not ==([]("1")) [](1, 2, 3) should not ==([]("1", "2", "3")) - - should return false when the two lists have different length
[ show source ]
[](1) should not ==([]) [](1) should not ==([](1, 2, 3))
- - should return true if the elements in the list are the same
[ show source ]
[](1) should ==([](1)) []("1") should ==([]("1")) [](1, 2, 3, 4, 5, 6, 7) should ==([](1, 2, 3, 4, 5, 6, 7)) - - should do the comparison using recursive applications of ==
[ show source ]
x = Origin mimic x == = method(o, o ==(42)) [](x) should ==([](42))
nil
[ show source ]
method(other,
if(self same?(
[]),
Reflector other:mimics?(cell(:other),
[]),
bind(rescue(Condition Error, fn(c, false)),
self ==(
other))))
- - should return false for something not in the list
[ show source ]
([] ===(:foo)) should be false ([](1) ===(2)) should be false ([](1, :foo, "bar") ===([](2))) should be false
- - should return true for the same list
[ show source ]
([](:foo) ===([](:foo))) should be true ([](1, 2) ===([](1, 2))) should be true ([](2, 1, :foo, "bar") ===([](2, 1, :foo, "bar"))) should be true
- - should return true when called against List and the other is a list
[ show source ]
(List ===(List)) should be true (List ===([])) should be true (List ===([](1, 2, 3))) should be true (List ===([](:foo))) should be true
- - should return true when called against List and the other is not a list
[ show source ]
(List ===(set)) should be false (List ===(1 ..(5))) should be false (List ===(:foo)) should be false
if this list is not empty, returns the result of evaluating the argument, otherwise returns the list
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
then = call arguments [](
0)
unless(empty?,
call argAt(0),
self),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should just return itself if empty
[ show source ]
([] ?&(42)) should ==([]) ([] ?&([](1, 2, 3))) should ==([])
- - should return the result of evaluating the code if non-empty
[ show source ]
[](1) ?&(10) should ==(10) [](1, 2, 3) ?&(20) should ==(20) x = [](1, 2) x ?&([](1, 2, 3)) should ==([](1, 2, 3))
if this list is empty, returns the result of evaluating the argument, otherwise returns the list
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
then = call arguments [](
0)
if(empty?,
call argAt(0),
self),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should just return itself if not empty
[ show source ]
[](1) ?|(x /(0)) should ==([](1)) [](1, 2, 3) ?|(x /(0)) should ==([](1, 2, 3)) x = [](1, 2) x ?|(blarg) should be same(x)
- - should return the result of evaluating the code if empty
[ show source ]
([] ?|(42)) should ==(42) ([] ?|([](1, 2, 3))) should ==([](1, 2, 3))
nil
- - should return nil if empty list when given a number
[ show source ]
list [](0) should be nil list [](10) should be nil list []((0 -(1))) should be nil
- - should return nil if argument is over the size when given a number
[ show source ]
list(1) [](1) should be nil
- - should return from the front if the argument is zero or positive when given a number
[ show source ]
[](1, 2, 3, 4) [](0) should ==(1) [](1, 2, 3, 4) [](1) should ==(2) [](1, 2, 3, 4) [](2) should ==(3) [](1, 2, 3, 4) [](3) should ==(4)
- - should return from the back if the argument is negative when given a number
[ show source ]
[](1, 2, 3, 4) [](0 -(1)) should ==(4) [](1, 2, 3, 4) [](0 -(2)) should ==(3) [](1, 2, 3, 4) [](0 -(3)) should ==(2) [](1, 2, 3, 4) [](0 -(4)) should ==(1)
- - should return an empty list for any range given to an empty list when given a number
[ show source ]
[] [](0 ..(0)) should ==([]) [] [](0 ...(0)) should ==([]) [] [](0 ..(-(1))) should ==([]) [] [](0 ...(-(1))) should ==([]) [] [](10 ..(20)) should ==([]) [] [](10 ...(20)) should ==([]) [] [](-(1) ..(20)) should ==([])
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:("[]"), 0) - - should validate type of argument
[ show source ]
fn([] []([])) should signal(Condition Error Type IncorrectType)
- - should return an equal list for 0..-1
[ show source ]
[] [](0 ..(-(1))) should ==([]) [](1, 2, 3) [](0 ..(-(1))) should ==([](1, 2, 3)) []("x", "y") [](0 ..(-(1))) should ==([]("x", "y")) - - should return all except the first element for 1..-1
[ show source ]
[](1) [](1 ..(-(1))) should ==([]) [](1, 2, 3) [](1 ..(-(1))) should ==([](2, 3)) []("x", "y") [](1 ..(-(1))) should ==([]("y")) - - should return all except for the first and last for 1...-1
[ show source ]
[](1, 2) [](1 ...(-(1))) should ==([]) [](1, 2, 3) [](1 ...(-(1))) should ==([](2)) []("x", "y", "zed", "bar") [](1 ...(-(1))) should ==([]("y", "zed")) - - should return an array with the first element for 0..0
[ show source ]
[](1) [](0 ..(0)) should ==([](1)) [](1, 2, 3) [](0 ..(0)) should ==([](1)) []("x", "y") [](0 ..(0)) should ==([]("x")) - - should return an empty array for 0...0
[ show source ]
[](1) [](0 ...(0)) should ==([]) [](1, 2, 3) [](0 ...(0)) should ==([]) []("x", "y") [](0 ...(0)) should ==([]) - - should return a slice from a larger array
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](3 ..(5)) should ==([](4, 5, 6))
- - should return a correct slice for an exclusive range
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](3 ...(6)) should ==([](4, 5, 6))
- - should return a correct slice for a slice that ends in a negative index
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](3 ..(-(3))) should ==([](4, 5, 6, 7, 8, 9))
- - should return a correct slice for an exclusive slice that ends in a negative index
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](3 ...(-(3))) should ==([](4, 5, 6, 7, 8))
- - should return all elements up to the end of the slice, if the end argument is way out there
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](5 ..(3443343)) should ==([](6, 7, 8, 9, 10, 11)) [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](5 ...(3443343)) should ==([](6, 7, 8, 9, 10, 11))
- - should return an empty array for a totally messed up indexing
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](-(1) ..(3)) should ==([]) [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](-(1) ..(7557)) should ==([]) [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](5 ..(4)) should ==([]) [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](-(1) ...(3)) should ==([]) [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](-(1) ...(7557)) should ==([]) [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) [](5 ...(4)) should ==([])
nil
- - should set the first element in an empty list
[ show source ]
x = [] x [](0) = 42 x length should ==(1) x [](0) should ==(42)
- - should overwrite an existing element
[ show source ]
x = [](40) x [](0) = 42 x length should ==(1) x [](0) should ==(42)
- - should expand the list up to the point where the element fits, if the index is further away
[ show source ]
x = [](40, 42) x [](10) = 45 x length should ==(11) x [](0) should ==(40) x [](1) should ==(42) x [](2) should be nil x [](3) should be nil x [](4) should be nil x [](5) should be nil x [](6) should be nil x [](7) should be nil x [](8) should be nil x [](9) should be nil x [](10) should ==(45)
- - should be possible to set with negative indices
[ show source ]
x = [](40, 42, 44, 46) x [](-(2)) = 52 x length should ==(4) x [](0) should ==(40) x [](1) should ==(42) x [](2) should ==(52) x [](3) should ==(46)
- - should return the value set
[ show source ]
([](40, 42, 44, 46) [](0) = 33 +(44)) should ==(77)
- - should throw an exception if setting with negative indices outside the range
[ show source ]
fn([] [](0 -(1)) = 52) should signal(Condition Error Index)
- - should validate type of receiver
[ show source ]
[](0, 1) should checkReceiverTypeOn(:("[]="), 0, 3) - - should validate type of argument
[ show source ]
fn([] [](:boris) = :beans) should signal(Condition Error Type IncorrectType)
takes one argument and adds it at the end of the list, and then returns the list
- - should add an element to an empty list
[ show source ]
l = [] l append!(:foo) l should ==([](:foo))
- - should add an element at the end of a list with elements in it
[ show source ]
l = [](:foo, :bar, 1, 42) l append!(:flax) l should ==([](:foo, :bar, 1, 42, :flax))
- - should add an element several times if asked to
[ show source ]
l = [](:foo) l append!(:foo) l append!(:foo) l append!(:foo) l append!(:foo) l should ==([](:foo, :foo, :foo, :foo, :foo))
- - should return the list
[ show source ]
l = [] l append!(:foo) should ==(l)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:append!, 0)
takes an object, and returns the first list in this list that has that object as its first element. if it can't be found, returns nil.
[ show source ]
method(obj,
self find(el,
el mimics?(List) &&(el length >(0)) &&(el [](0) ==(obj))))
- - should return nil for an empty list
[ show source ]
[] assoc(:foo) should be nil
- - should return nil for a list where it can't find the argument
[ show source ]
[]([](:bar), [](:blah)) assoc(:foo) should be nil
- - should not fail for a list that includes stuff that isn't lists
[ show source ]
[](1, 2, 3, 4) assoc(:foo) should be nil
- - should return a list if it matches
[ show source ]
[]([](:abc), [](:foo, 1, 2), [](:blah)) assoc(:foo) should ==([](:foo, 1, 2))
- - should return the first list that matches
[ show source ]
[]([](:abc), [](:foo, 1, 2), [](:blah), [](:foo, 3, 2)) assoc(:foo) should ==([](:foo, 1, 2))
takes one argument, the index of the element to be returned. can be negative, and will in that case return indexed from the back of the list. if the index is outside the bounds of the list, will return nil. the argument can also be a range, and will in that case interpret the first index as where to start, and the second the end. the end can be negative and will in that case be from the end. if the first argument is negative, or after the second, an empty list will be returned. if the end point is larger than the list, the size of the list will be used as the end point.
- - should return nil if empty list
[ show source ]
list at(0) should be nil list at(10) should be nil list at(0 -(1)) should be nil
- - should return nil if argument is over the size
[ show source ]
list(1) at(1) should be nil
- - should return from the front if the argument is zero or positive
[ show source ]
[](1, 2, 3, 4) at(0) should ==(1) [](1, 2, 3, 4) at(1) should ==(2) [](1, 2, 3, 4) at(2) should ==(3) [](1, 2, 3, 4) at(3) should ==(4)
- - should return from the back if the argument is negative
[ show source ]
[](1, 2, 3, 4) at(0 -(1)) should ==(4) [](1, 2, 3, 4) at(0 -(2)) should ==(3) [](1, 2, 3, 4) at(0 -(3)) should ==(2) [](1, 2, 3, 4) at(0 -(4)) should ==(1)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:at, 0)
- - should validate type of argument
[ show source ]
fn([] at([])) should signal(Condition Error Type IncorrectType)
takes two arguments, the index of the element to set, and the value to set. the index can be negative and will in that case set indexed from the end of the list. if the index is larger than the current size, the list will be expanded with nils. an exception will be raised if a abs(negative index) is larger than the size.
- - should set the first element in an empty list
[ show source ]
x = [] x at(0) = 42 x length should ==(1) x [](0) should ==(42)
- - should overwrite an existing element
[ show source ]
x = [](40) x at(0) = 42 x length should ==(1) x [](0) should ==(42)
- - should expand the list up to the point where the element fits, if the index is further away
[ show source ]
x = [](40, 42) x at(10) = 45 x length should ==(11) x [](0) should ==(40) x [](1) should ==(42) x [](2) should be nil x [](3) should be nil x [](4) should be nil x [](5) should be nil x [](6) should be nil x [](7) should be nil x [](8) should be nil x [](9) should be nil x [](10) should ==(45)
- - should be possible to set with negative indices
[ show source ]
x = [](40, 42, 44, 46) x at(-(2)) = 52 x length should ==(4) x [](0) should ==(40) x [](1) should ==(42) x [](2) should ==(52) x [](3) should ==(46)
- - should return the value set
[ show source ]
([](40, 42, 44, 46) at(0) = 33 +(44)) should ==(77)
- - should throw an exception if setting with negative indices outside the range
[ show source ]
fn([] [](-(1)) = 52) should signal(Condition Error Index)
- - should validate type of receiver
[ show source ]
[](0, 1) should checkReceiverTypeOn(:("at="), 0, 3) - - should validate type of argument
[ show source ]
fn([] at(:stilton) = :gouda) should signal(Condition Error Type IncorrectType)
returns all the entries in the list, except for the 'n' last one, where 'n' is an optional argument that defaults to 1.
[ show source ]
method(n 1,
end = length -(n)
if(end <(0) ||(empty?),
DefaultBehavior [],
[](0 ...(end))))
- - should return an empty list for the empty list
[ show source ]
[] butLast should ==([])
- - should return an empty list for a list with one entry
[ show source ]
[](1) butLast should ==([])
- - should return a list with the first entry for a list with two elements
[ show source ]
[](1, 2) butLast should ==([](1))
- - should return an empty list for a list with two elements when given 2 as an argument
[ show source ]
[](1, 2) butLast(2) should ==([])
- - should return a list with several entries for a longer list, without arguments
[ show source ]
[](1, 2, 3, 4, 5, 6) butLast should ==([](1, 2, 3, 4, 5))
- - should return a list with several entries for a longer list, with an argument of 3
[ show source ]
[](1, 2, 3, 4, 5, 6, 7) butLast(3) should ==([](1, 2, 3, 4))
- - should return the list with the same entries for an argument of zero
[ show source ]
[](1, 2, 3, 4, 5, 6) butLast(0) should ==([](1, 2, 3, 4, 5, 6))
chooses a random element from the list. If a quantity is specified it returns a sequence of random elements each chosen from the complete list (and therefore may contain duplicates)
[ show source ]
method(quantity nil,
if(quantity,
outerList = self
left = quantity
Sequence with(
next?: fnx(left >(0)),
next: fnx(--(left)
outerList random)),
random))
- - should take zero arguments and return a random element from the list
[ show source ]
l = [](:sam, :sooze, :beans) p = l choose l should include(p)
- - should take one argument specifying the quantity and return a sequence containing that many random elements
[ show source ]
l = [](:sam, :sooze, :beans) s = l choose(3) s next? should ==(true) taken = s take(3) taken length should ==(3) taken each(el, l should include(el))
- - should not modify the original list
[ show source ]
l = [](:sam, :sooze, :beans) l choose l length should ==(3) l should ==([](:sam, :sooze, :beans)) l = [](:sam, :sooze, :beans) l choose(3) l length should ==(3) l should ==([](:sam, :sooze, :beans))
will remove all the entries from the list, and then returns the list
- - should not do anything on an empty list
[ show source ]
x = [] x clear! x size should ==(0)
- - should clear a list that has entries
[ show source ]
x = [](1, 2, 3, 4) x clear! x size should ==(0)
- - should return the list
[ show source ]
x = [](1, 2, 3, 4) x clear! should ==(x)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:clear!)
nil
- - should return an empty list for an empty enumerable
[ show source ]
[] collect!(x, x +(2)) should ==([])
- - should return the same list for something that only returns itself
[ show source ]
[](1, 2, 3) collect!(x, x) should ==([](1, 2, 3))
- - should take one argument and apply the inside
[ show source ]
[](1, 2, 3) collect!(+(2)) should ==([](3, 4, 5)) [](1, 2, 3) collect!(1) should ==([](1, 1, 1))
- - should take two arguments and apply the code with the argument name bound
[ show source ]
[](1, 2, 3) collect!(x, x +(3)) should ==([](4, 5, 6)) [](1, 2, 3) collect!(x, 1) should ==([](1, 1, 1))
- - should return the origin list
[ show source ]
x = [](1, 2, 3) x collect!(x, 1) should be same(x)
- - should modify the original list
[ show source ]
x = [](1, 2, 3) x collect!(x, 1) x should ==([](1, 1, 1))
returns a new list that is a mimic of the current list, except that all nils are removed from it
[ show source ]
method( newList = self mimic newList compact! newList)
- - should return an empty list for an empty list
[ show source ]
[] compact should ==([])
- - should return a list without nils
[ show source ]
[](nil) compact should ==([]) [](nil, 1) compact should ==([](1)) [](1, nil, 1) compact should ==([](1, 1)) [](1, nil) compact should ==([](1)) [](1, 2, 3, :nil, nil, nil, nil, nil, :bah, nil) compact should ==([](1, 2, 3, :nil, :bah))
- - should leave a list without nils unmodified
[ show source ]
[](:a) compact should ==([](:a)) [](:a, :b, 123) compact should ==([](:a, :b, 123))
- - should not remove false values
[ show source ]
[](false) compact should ==([](false))
- - should not modify the original list
[ show source ]
x = [](nil, 1) x compact x should ==([](nil, 1))
removes all nils in this list, and then returns the list
- - should return the list
[ show source ]
x = [](1, 2, 3) x compact! should be same(x)
- - should leave an empty list unmodified
[ show source ]
x = [] x compact! x should ==([])
- - should remove all nils in the list
[ show source ]
[](nil) compact! should ==([]) [](nil, 1) compact! should ==([](1)) [](1, nil, 1) compact! should ==([](1, 1)) [](1, nil) compact! should ==([](1)) [](1, 2, 3, :nil, nil, nil, nil, nil, :bah, nil) compact! should ==([](1, 2, 3, :nil, :bah))
- - should leave a list without nils unmodified
[ show source ]
[](:a) compact! should ==([](:a)) [](:a, :b, 123) compact! should ==([](:a, :b, 123))
- - should not remove false values
[ show source ]
[](false) compact! should ==([](false))
- - should modify the original list
[ show source ]
x = [](1, nil) x compact! x should ==([](1))
adds the elements in the argument list to the current list, and then returns that list
- - should change nothing for an empty list
[ show source ]
x = [](1) x concat!([]) x should ==([](1))
- - should append the other list
[ show source ]
[] concat!([](1)) should ==([](1)) [](:foo, [](:abc)) concat!([]([](:blarg), 1)) should ==([](:foo, [](:abc), [](:blarg), 1))
- - should modify the receiver
[ show source ]
x = [](1) x concat!([](2)) x should ==([](1, 2))
- - should return the list
[ show source ]
x = [](1) x concat!([](2)) should be same(x)
takes either one or two or three arguments. if one argument is given, it should be a message chain that will be sent to each object in the list. the result will be thrown away. if two arguments are given, the first is an unevaluated name that will be set to each of the values in the list in succession, and then the second argument will be evaluated in a scope with that argument in it. if three arguments is given, the first one is an unevaluated name that will be set to the index of each element, and the other two arguments are the name of the argument for the value, and the actual code. the code will evaluate in a lexical context, and if the argument name is available outside the context, it will be shadowed. the method will return the list.
- - should return a seq when given no arguments
[ show source ]
x = [] each x should mimic(Sequence)
- - should not do anything for an empty list
[ show source ]
x = 0 [] each(++(x)) x should ==(0)
- - should be possible to just give it a message chain, that will be invoked on each object
[ show source ]
Ground y = [] Ground xs = method(y <<(self)) [](1, 2, 3) each(xs) y should ==([](1, 2, 3)) x = 0 [](1, 2, 3) each(nil ++(x)) x should ==(3)
- - should be possible to give it an argument name, and code
[ show source ]
y = [] [](1, 2, 3) each(x, y <<(x)) y should ==([](1, 2, 3))
- - should return the object
[ show source ]
y = [](1, 2, 3) (y each(x, x)) should be(y)
- - should establish a lexical context when invoking the methods. this context will be the same for all invocations.
[ show source ]
[](1, 2, 3) each(x_list, blarg = 32) cell?(:x_list) should be false cell?(:blarg) should be false x = 14 [](1, 2, 3) each(x, blarg = 32) x should ==(14)
- - should be possible to give it an extra argument to get the index
[ show source ]
y = [] [](1, 2, 3, 4) each(i, x, y <<([](i, x))) y should ==([]([](0, 1), [](1, 2), [](2, 3), [](3, 4)))
- - should yield lists if running over a list of lists
[ show source ]
y = [] []([](1), [](2), [](3)) each(x, y <<(x)) y should ==([]([](1), [](2), [](3)))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:each, 1)
returns true if this list is empty, false otherwise
- - should return true for an empty list
[ show source ]
x = [] x empty? should be true
- - should return false for an non empty list
[ show source ]
x = [](1) x empty? should be false x = []("abc", "cde") x empty? should be false - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:empty?)
returns a new list that is a mimic of the current list, with all elements flattened in it
[ show source ]
method( newList = self mimic newList flatten! newList)
- - should return an empty list for an empty list
[ show source ]
[] flatten should ==([])
- - should not touch non-list elements
[ show source ]
[](1, 2, 3, :foo) flatten should ==([](1, 2, 3, :foo)) [](1, 2, 3, set(:foo)) flatten should ==([](1, 2, 3, set(:foo)))
- - should flatten all lists into the end result, recursively
[ show source ]
[]([](1)) flatten should ==([](1)) [](2, [](1), 1) flatten should ==([](2, 1, 1)) []([](2, [](1)), 1) flatten should ==([](2, 1, 1)) []([](2, [](1)), []([](1))) flatten should ==([](2, 1, 1)) []([]([](2, [](1)), []([](1)))) flatten should ==([](2, 1, 1))
- - should not modify the receiver
[ show source ]
x = []([](1)) x flatten x should ==([]([](1)))
- - should not modify any of the internal lists
[ show source ]
int = [](1, [](2), 3) x = [](int, int) x flatten int should ==([](1, [](2), 3))
flattens all lists in this list recursively, then returns it
- - should return an empty list for an empty list
[ show source ]
[] flatten! should ==([])
- - should not touch non-list elements
[ show source ]
[](1, 2, 3, :foo) flatten! should ==([](1, 2, 3, :foo)) [](1, 2, 3, set(:foo)) flatten! should ==([](1, 2, 3, set(:foo)))
- - should flatten all lists into the end result, recursively
[ show source ]
[]([](1)) flatten! should ==([](1)) [](2, [](1), 1) flatten! should ==([](2, 1, 1)) []([](2, [](1)), 1) flatten! should ==([](2, 1, 1)) []([](2, [](1)), []([](1))) flatten! should ==([](2, 1, 1)) []([]([](2, [](1)), []([](1)))) flatten! should ==([](2, 1, 1))
- - should modify the receiver
[ show source ]
x = []([](1)) x flatten! x should ==([](1))
- - should return the receiver
[ show source ]
x = []([](1)) x flatten! should be same(x)
- - should not modify any of the internal lists
[ show source ]
int = [](1, [](2), 3) x = [](int, int) x flatten! int should ==([](1, [](2), 3))
returns a hash for the list
- - should return the same number for equal lists
[ show source ]
[] hash should ==([] hash) x = [](1) y = [] y <<(1) x hash should ==(y hash) x hash should not ==([] hash)
- - should return different numbers for different lists
[ show source ]
[](1) hash should not ==([]("1") hash) [] hash should not ==([](1) hash) [](1) hash should not ==([] hash) - - should do the computation using recursive applications of hash
[ show source ]
x = Origin mimic y = Origin mimic [](x) hash should not ==([](y)) x hash = method(42) y hash = method(42) [](x) hash should ==([](y) hash)
if this list is empty, returns the result of evaluating the argument, otherwise returns the list
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
then = call arguments [](
0)
if(empty?,
call argAt(0),
self),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should just return itself if not empty
[ show source ]
[](1) ifEmpty(x /(0)) should ==([](1)) [](1, 2, 3) ifEmpty(x /(0)) should ==([](1, 2, 3)) x = [](1, 2) x ifEmpty(blarg) should be same(x)
- - should return the result of evaluating the code if empty
[ show source ]
[] ifEmpty(42) should ==(42) [] ifEmpty([](1, 2, 3)) should ==([](1, 2, 3))
returns true if the receiver includes the evaluated argument, otherwise false
- - should return false for something not in the list
[ show source ]
[] include?(:foo) should be false [](1) include?(2) should be false [](1, :foo, "bar") include?(2) should be false
- - should return true for something in the list
[ show source ]
[](:foo) include?(:foo) should be true [](1, 2) include?(2) should be true [](2, 1, :foo, "bar") include?(2) should be true
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:include?, "Richard Richard")
takes an object and returns the index of the first occurance of that object in this list, or nil if it doesn't exist
[ show source ]
method(obj,
self each(index, element,
if(element ==(obj),
return(index)))
nil)
- - should return the index of the first element == to object
[ show source ]
x = Origin mimic x == = method(obj, 3 ==(obj)) [](2, x, 3, 1, 3, 1) index(3) should ==(1)
- - should return 0 if first element == to object
[ show source ]
[](2, 1, 3, 2, 5) index(2) should ==(0)
- - should return size-1 if only last element == to object
[ show source ]
[](2, 1, 3, 1, 5) index(5) should ==(4)
- - should return nil if no element == to object
[ show source ]
[](2, 1, 1, 1, 1) index(3) should be nil
takes an index and zero or more objects to insert at that point. the index can be negative to index from the end of the list. if the index is positive and larger than the size of the list, the list will be filled with nils inbetween.
- - inserts objects before the element at index for non-negative index
[ show source ]
ary = [] ary insert!(0, 3) should ==(ary) ary should ==([](3)) ary insert!(0, 1, 2) should ==(ary) ary should ==([](1, 2, 3)) ary insert!(0) ary should ==([](1, 2, 3)) ary insert!(1, :a) should ==([](1, :a, 2, 3)) ary insert!(0, :b) should ==([](:b, 1, :a, 2, 3)) ary insert!(5, :c) should ==([](:b, 1, :a, 2, 3, :c)) ary insert!(7, :d) should ==([](:b, 1, :a, 2, 3, :c, nil, :d)) ary insert!(10, 5, 4) should ==([](:b, 1, :a, 2, 3, :c, nil, :d, nil, nil, 5, 4))
- - appends objects to the end of the array for index == -1
[ show source ]
[](1, 3, 3) insert!(-(1), 2, :x, 5) should ==([](1, 3, 3, 2, :x, 5))
- - inserts objects after the element at index with negative index
[ show source ]
ary = [] ary insert!(-(1), 3) should ==([](3)) ary insert!(-(2), 2) should ==([](2, 3)) ary insert!(-(3), 1) should ==([](1, 2, 3)) ary insert!(-(2), -(3)) should ==([](1, 2, -(3), 3)) ary insert!(-(1), []) should ==([](1, 2, -(3), 3, [])) ary insert!(-(2), :x, :y) should ==([](1, 2, -(3), 3, :x, :y, []))
- - pads with nils if the index to be inserted to is past the end
[ show source ]
[] insert!(5, 5) should ==([](nil, nil, nil, nil, nil, 5))
- - can insert before the first element with a negative index
[ show source ]
[](1, 2, 3) insert!(-(4), -(3)) should ==([](-(3), 1, 2, 3))
- - raises an IndexError if the negative index is out of bounds
[ show source ]
fn([] insert!(-(2), 1)) should signal(Condition Error Index) fn([](1) insert!(-(3), 2)) should signal(Condition Error Index)
- - does nothing if no object is passed
[ show source ]
[] insert!(0) should ==([]) [] insert!(-(1)) should ==([]) [] insert!(10) should ==([]) [] insert!(-(2)) should ==([])
Returns a text inspection of the object
- - should return something within square brackets
[ show source ]
[] inspect should ==("[]") - - should return the inspect format of things inside
[ show source ]
[](method(nil), method(f, f b), fn(a b)) inspect should ==("[method(nil), method(f, f b), fn(a b)]") - - should return the list of elements separated with ,
[ show source ]
[](1, 2, :foo, "bar") inspect should ==("[1, 2, :foo, \"bar\"]") - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:inspect)
returns a text composed of the asText representation of all elements in the list, separated by the separator. the separator defaults to an empty text.
- - returns an empty text if the List is empty
[ show source ]
a = [] a join should ==("") - - returns a text formed by concatenating each element asText separated by separator without trailing separator
[ show source ]
obj = Origin with(asText: "foo") [](1, 2, 3, 4, obj) join(" | ") should ==("1 | 2 | 3 | 4 | foo") - - uses the same separator with nested list
[ show source ]
[](1, [](2, [](3, 4), 5), 6) join(":") should ==("1:2:3:4:5:6") - - should default to the empty text as separator
[ show source ]
[](1, 2, 3) join should ==("123") - - does not process the separator if the list is empty
[ show source ]
a = [] sep = Origin mimic a join(sep) should ==("")
returns the last element of this list, or nil of the list is empty
[ show source ]
method( if(empty?, nil, [](0 -(1))))
- - should return nil for an empty list
[ show source ]
[] last should be nil
- - should return the only entry for a list with one element
[ show source ]
[](45) last should ==(45)
- - should return the last entry for a list with more than one entry
[ show source ]
[](33, 15, 45, 57) last should ==(57)
nil
- - should return zero for an empty list
[ show source ]
x = [] x length should ==(0)
- - should return the size for a non-empty list
[ show source ]
[](1) length should ==(1) []("abc", "cde") length should ==(2) - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:length)
takes one or two arguments, and will then use these arguments as code to transform each element in this list. the transform happens in place. finally the method will return the receiver.
- - should return an empty list for an empty enumerable
[ show source ]
[] map!(x, x +(2)) should ==([])
- - should return the same list for something that only returns itself
[ show source ]
[](1, 2, 3) map!(x, x) should ==([](1, 2, 3))
- - should take one argument and apply the inside
[ show source ]
[](1, 2, 3) map!(+(2)) should ==([](3, 4, 5)) [](1, 2, 3) map!(1) should ==([](1, 1, 1))
- - should take two arguments and apply the code with the argument name bound
[ show source ]
[](1, 2, 3) map!(x, x +(3)) should ==([](4, 5, 6)) [](1, 2, 3) map!(x, 1) should ==([](1, 1, 1))
- - should return the origin list
[ show source ]
x = [](1, 2, 3) x map!(x, 1) should be same(x)
- - should modify the original list
[ show source ]
x = [](1, 2, 3) x map!(x, 1) x should ==([](1, 1, 1))
Returns a brief text inspection of the object
- - should return something within square brackets
[ show source ]
[] notice should ==("[]") - - should return the notice format of things inside
[ show source ]
[](method, method, fn) notice should ==("[method(...), method(...), fn(...)]") - - should return the list of elements separated with ,
[ show source ]
[](1, 2, :foo, "bar") notice should ==("[1, 2, :foo, \"bar\"]") - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:notice)
picks a random element from the list. If a quantity is specified it returns a list of that size picked randomly which is a subset of the original list. If the specified quantity is greater than the length of the list, the returned list will be padded with nils.
[ show source ]
method(quantity nil,
if(quantity,
result = list
notPicked = self mimic
quantity times(
result <<(notPicked removeAt!(System randomNumber %(notPicked length))))
result,
random))
- - should take zero arguments and return a random element from the list
[ show source ]
l = [](:sam, :sooze, :beans) p = l pick l should include(p)
- - should take one argument and return a subset list of that length, padded with nils if necessary
[ show source ]
l = [](:sam, :sooze, :beans) l pick(1) length should ==(1) l pick(2) length should ==(2) l pick(100) length should ==(100) l pick(2) each(el, l should include(el)) l pick(l length) sort should ==(l sort) (l pick(7) -(l)) should ==([](nil, nil, nil, nil))
- - should not modify the original list
[ show source ]
l = [](:sam, :sooze, :beans) l pick(2) l should ==([](:sam, :sooze, :beans))
picks and removes a random element from the list. If a quantity is specified it modifies the list by removing that many random elements and returning them in a new list. If the specified quantity is greater than the length of the list, the returned list will be padded with nils.
[ show source ]
method(quantity nil,
if(quantity,
result = list
quantity times(
if(length >(0),
result <<(removeAt!(randomIndex)),
result <<(nil)))
result,
removeAt!(randomIndex)))
- - should take zero arguments and remove and return a random element from the list
[ show source ]
l = [](:sam, :sooze, :beans) p = l pick! [](:sam, :sooze, :beans) should include(p)
- - should take one argument and return a subset list of that length, padded with nils if necessary
[ show source ]
[](:sam, :sooze, :beans) pick!(1) length should ==(1) [](:sam, :sooze, :beans) pick!(2) length should ==(2) [](:sam, :sooze, :beans) pick!(100) length should ==(100) [](:sam, :sooze, :beans) pick!(2) each(el, [](:sam, :sooze, :beans) should include(el)) [](:sam, :sooze, :beans) pick!(3) sort should ==([](:sam, :sooze, :beans) sort) ([](:sam, :sooze, :beans) pick!(7) -([](:sam, :sooze, :beans))) should ==([](nil, nil, nil, nil))
- - should modify the original list
[ show source ]
l = [](:sam, :sooze, :beans) l pick! l should not ==([](:sam, :sooze, :beans)) l size should ==(2) l2 = [](:sam, :sooze, :beans) l2 pick!(2) l2 should not ==([](:sam, :sooze, :beans)) l2 size should ==(1)
removes the last element from the list and returns it. returns nil if the list is empty.
- - should return nil for an empty list
[ show source ]
[] pop! should be nil
- - should return the element for a list with one element
[ show source ]
[](:blarg) pop! should ==(:blarg)
- - should remove the element in a list with one element
[ show source ]
l = [](:blarg) l pop! l should ==([])
- - should return the last element for a list with more than one element
[ show source ]
[](:blem, :flag, :moppy) pop! should ==(:moppy)
- - should remove the last element in a list with more than one element
[ show source ]
l = [](:blem, :flag, :moppy) l pop! l should ==([](:blem, :flag)) l pop! l should ==([](:blem))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:pop!)
takes one argument and adds it at the beginning of the list, and then returns the list
- - should add an element to an empty list
[ show source ]
l = [] l prepend!(:foo) l should ==([](:foo))
- - should add an element at the beginning of a list with elements in it
[ show source ]
l = [](:foo, :bar, 1, 42) l prepend!(:flax) l should ==([](:flax, :foo, :bar, 1, 42))
- - should add an element several times if asked to
[ show source ]
l = [](:foo) l prepend!(:foo) l prepend!(:foo) l prepend!(:foo) l prepend!(:foo) l should ==([](:foo, :foo, :foo, :foo, :foo))
- - should return the list
[ show source ]
l = [] l prepend!(:foo) should ==(l)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:prepend!, 0)
nil
- - should add an element to an empty list
[ show source ]
l = [] l push!(:foo) l should ==([](:foo))
- - should add an element at the end of a list with elements in it
[ show source ]
l = [](:foo, :bar, 1, 42) l push!(:flax) l should ==([](:foo, :bar, 1, 42, :flax))
- - should add an element several times if asked to
[ show source ]
l = [](:foo) l push!(:foo) l push!(:foo) l push!(:foo) l push!(:foo) l should ==([](:foo, :foo, :foo, :foo, :foo))
- - should return the list
[ show source ]
l = [] l push!(:foo) should ==(l)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:push!, 0)
returns a random element from the list. Returns nil if the list is empty.
[ show source ]
method(
if(length >(0),
[](System randomNumber %(length)),
nil))
- - should return an element from the list
[ show source ]
l = [](:sam, :sooze, :beans) r = l random l should include(r)
- - should return nil if the list is empty
[ show source ]
[] random should be nil
returns the index of a random element from the list. Returns nil if the list is empty.
[ show source ]
method(
if(length >(0),
System randomNumber %(length),
nil))
- - should return an integer within the range (0..list length)
[ show source ]
l = [](:sam, :sooze, :beans) r = l randomIndex (0 ..(l length)) asList should include(r)
- - should return nil if the list is empty
[ show source ]
[] randomIndex should be nil
takes an object, and returns the first list in this list that has that object as its second element. if it can't be found, returns nil.
[ show source ]
method(obj,
self find(el,
el mimics?(List) &&(el length >(1)) &&(el [](1) ==(obj))))
- - should return nil for an empty list
[ show source ]
[] rassoc(:foo) should be nil
- - should return nil for a list where it can't find the argument
[ show source ]
[]([](1, :bar), [](2, :blah)) rassoc(:foo) should be nil
- - should not fail for a list that includes stuff that isn't lists
[ show source ]
[](1, 2, 3, 4) rassoc(:foo) should be nil
- - should return a list if it matches
[ show source ]
[]([](1, :abc), [](2, :foo, 1, 2), [](3, :blah)) rassoc(:foo) should ==([](2, :foo, 1, 2))
- - should return the first list that matches
[ show source ]
[]([](1, :abc), [](2, :foo, 1, 2), [](3, :blah), [](4, :foo, 3, 2)) rassoc(:foo) should ==([](2, :foo, 1, 2))
takes one or more arguments. removes all occurrences of the provided arguments from the list and returns the updated list. if an argument is not contained, the list remains unchanged. sending this method to an empty list has no effect.
- - should return empty list if receiver is empty list
[ show source ]
[] remove!(1) should ==([]) [] remove!("a") should ==([]) [] remove!(1, 2) should ==([]) [] remove!("a", "b") should ==([]) - - should remove all occurrences of single argument
[ show source ]
[](1, 2, 3, 4, 1, 2, 3, 4) remove!(2) should ==([](1, 3, 4, 1, 3, 4)) []("a", "b", "c", "a", "b", "c") remove!("b") should ==([]("a", "c", "a", "c")) - - should remove all occurrences of multiple arguments
[ show source ]
[](1, 2, 3, 4, 1, 2, 3, 4) remove!(1, 3) should ==([](2, 4, 2, 4)) [](1, 2, 3, 4, 1, 2, 3, 4) remove!(1, 2, 3, 4) should ==([]) []("a", "b", "c", "a", "b", "c") remove!("a", "b", "c") should ==([]) []("a", "b", "c", "a", "b", "c") remove!("a", "b") should ==([]("c", "c")) - - should leave list unmodified if arguments not contained in list
[ show source ]
[](1, 2, 3, 4) remove!(5) should ==([](1, 2, 3, 4)) [](1, 2, 3, 4) remove!(5, 6, 7) should ==([](1, 2, 3, 4)) []("a", "b", "c") remove!("x") should ==([]("a", "b", "c")) []("a", "b", "c") remove!("x", "y", "z") should ==([]("a", "b", "c")) - - should skip arguments not contained in list
[ show source ]
[](1, 2, 3, 4, 1, 2, 3, 4) remove!(2, 3, 5, 6) should ==([](1, 4, 1, 4)) []("a", "b", "c", "a", "b", "c") remove!("a", "b", "x", "y") should ==([]("c", "c")) - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:remove!, 0)
takes as argument the index of the element to be removed and returns it. can be negative and will in that case index from the back of the list. if the index is outside the bounds of the list, will return nil. the argument can also be a range, and will in that case remove the sublist beginning at the first index and extending to the position in the list specified by the second index (inclusive or exclusive depending on the range). the end of the range can be negative and will in that case index from the back of the list. if the start of the range is negative, or greater than the end, an empty list will be returned. if the end index exceeds the bounds of the list, its size will be used instead.
- - should return nil if receiver is empty list
[ show source ]
list removeAt!(0) should be nil list removeAt!(10) should be nil list removeAt!(-(1)) should be nil
- - should return nil if argument is greater than the list's size
[ show source ]
list(1) removeAt!(1) should be nil
- - should remove element from front if argument is zero or positive
[ show source ]
l = [](1, 2, 3, 4) l removeAt!(0) should ==(1) l should ==([](2, 3, 4)) l = [](1, 2, 3, 4) l removeAt!(1) should ==(2) l should ==([](1, 3, 4)) l = [](1, 2, 3, 4) l removeAt!(2) should ==(3) l should ==([](1, 2, 4)) l = [](1, 2, 3, 4) l removeAt!(3) should ==(4) l should ==([](1, 2, 3))
- - should remove element from back if argument is negative
[ show source ]
l = [](1, 2, 3, 4) l removeAt!(-(1)) should ==(4) l should ==([](1, 2, 3)) l = [](1, 2, 3, 4) l removeAt!(-(2)) should ==(3) l should ==([](1, 2, 4)) l = [](1, 2, 3, 4) l removeAt!(-(3)) should ==(2) l should ==([](1, 3, 4)) l = [](1, 2, 3, 4) l removeAt!(-(4)) should ==(1) l should ==([](2, 3, 4))
- - should not remove anything for any range if reveicer is empty list
[ show source ]
l = [] l removeAt!(0 ..(0)) should ==([]) l should ==([]) l = [] l removeAt!(0 ...(0)) should ==([]) l should ==([]) l = [] l removeAt!(0 ..(-(1))) should ==([]) l should ==([]) l = [] l removeAt!(0 ...(-(1))) should ==([]) l should ==([]) l = [] l removeAt!(10 ..(20)) should ==([]) l should ==([]) l = [] l removeAt!(10 ...(20)) should ==([]) l should ==([]) l = [] l removeAt!(-(1) ..(20)) should ==([]) l should ==([])
- - should remove all elements for 0..-1
[ show source ]
l = [] l removeAt!(0 ..(-(1))) should ==([]) l should ==([]) l = [](1, 2, 3) l removeAt!(0 ..(-(1))) should ==([](1, 2, 3)) l should ==([]) l = []("x", "y") l removeAt!(0 ..(-(1))) should ==([]("x", "y")) l should ==([]) - - should remove all except first element for 1..-1
[ show source ]
l = [](1) l removeAt!(1 ..(-(1))) should ==([]) l should ==([](1)) l = [](1, 2, 3) l removeAt!(1 ..(-(1))) should ==([](2, 3)) l should ==([](1)) l = []("x", "y") l removeAt!(1 ..(-(1))) should ==([]("y")) l should ==([]("x")) - - should remove all except first and last element for 1...-1
[ show source ]
l = [](1, 2) l removeAt!(1 ...(-(1))) should ==([]) l should ==([](1, 2)) l = [](1, 2, 3) l removeAt!(1 ...(-(1))) should ==([](2)) l should ==([](1, 3)) l = []("x", "y", "zed", "bar") l removeAt!(1 ...(-(1))) should ==([]("y", "zed")) l should ==([]("x", "bar")) - - should remove first element for 0..0
[ show source ]
l = [](1) l removeAt!(0 ..(0)) should ==([](1)) l should ==([]) l = [](1, 2, 3) l removeAt!(0 ..(0)) should ==([](1)) l should ==([](2, 3)) l = []("x", "y") l removeAt!(0 ..(0)) should ==([]("x")) l should ==([]("y")) - - should not remove anything for 0...0
[ show source ]
l = [](1) l removeAt!(0 ...(0)) should ==([]) l should ==([](1)) l = [](1, 2, 3) l removeAt!(0 ...(0)) should ==([]) l should ==([](1, 2, 3)) l = []("x", "y") l removeAt!(0 ...(0)) should ==([]) l should ==([]("x", "y")) - - should remove sublist for inclusive range
[ show source ]
l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(3 ..(5)) should ==([](4, 5, 6)) l should ==([](1, 2, 3, 7, 8, 9, 10, 11))
- - should remove sublist for exclusive range
[ show source ]
l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(3 ...(6)) should ==([](4, 5, 6)) l should ==([](1, 2, 3, 7, 8, 9, 10, 11))
- - should remove sublist for inclusive range that ends in negative index
[ show source ]
l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(3 ..(-(3))) should ==([](4, 5, 6, 7, 8, 9)) l should ==([](1, 2, 3, 10, 11))
- - should remove sublist for exclusive range that ends in negative index
[ show source ]
l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(3 ...(-(3))) should ==([](4, 5, 6, 7, 8)) l should ==([](1, 2, 3, 9, 10, 11))
- - should remove all elements to end of list for range that ends in index greater than list's size
[ show source ]
l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(5 ..(3443343)) should ==([](6, 7, 8, 9, 10, 11)) l should ==([](1, 2, 3, 4, 5)) l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(5 ...(3443343)) should ==([](6, 7, 8, 9, 10, 11)) l should ==([](1, 2, 3, 4, 5))
- - should not remove anything for a totally messed up indexing
[ show source ]
l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(-(1) ..(3)) should ==([]) l should ==([](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(-(1) ..(7557)) should ==([]) l should ==([](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(5 ..(4)) should ==([]) l should ==([](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(-(1) ...(3)) should ==([]) l should ==([](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(-(1) ...(7557)) should ==([]) l should ==([](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) l = [](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) l removeAt!(5 ...(4)) should ==([]) l should ==([](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:removeAt!, 0)
- - should validate type of argument
[ show source ]
fn([] removeAt!([])) should signal(Condition Error Type IncorrectType) fn([] removeAt!("foo")) should signal(Condition Error Type IncorrectType)
takes one or more arguments. removes the first occurrence of the provided arguments from the list and returns the updated list. if an argument is not contained, the list remains unchanged. arguments that are provided multiple times are treated as distinct elements. sending this message to an empty list has no effect.
- - should return empty list if receiver is empty list
[ show source ]
[] removeFirst!(1) should ==([]) [] removeFirst!("a") should ==([]) [] removeFirst!(1, 2) should ==([]) [] removeFirst!("a", "b") should ==([]) - - should remove first occurrence of single argument
[ show source ]
[](1, 2, 1, 2) removeFirst!(2) should ==([](1, 1, 2)) []("a", "b", "a", "b") removeFirst!("b") should ==([]("a", "a", "b")) - - should remove first occurrence of multiple arguments
[ show source ]
[](1, 2, 1, 2) removeFirst!(1, 2) should ==([](1, 2)) [](1, 2, 1, 2) removeFirst!(1, 1) should ==([](2, 2)) [](1, 2, 1, 2) removeFirst!(1, 2, 1, 2) should ==([]) []("a", "b", "a", "b") removeFirst!("a", "b") should ==([]("a", "b")) []("a", "b", "a", "b") removeFirst!("a", "a") should ==([]("b", "b")) []("a", "b", "a", "b") removeFirst!("a", "b", "a", "b") should ==([]) - - should leave list unmodified if arguments not contained in list
[ show source ]
[](1, 2, 3, 4) removeFirst!(5) should ==([](1, 2, 3, 4)) [](1, 2, 3, 4) removeFirst!(5, 6, 7) should ==([](1, 2, 3, 4)) []("a", "b", "c") removeFirst!("x") should ==([]("a", "b", "c")) []("a", "b", "c") removeFirst!("x", "y", "z") should ==([]("a", "b", "c")) - - should skip arguments not contained in list
[ show source ]
[](1, 2, 1, 2) removeFirst!(2, 5, 6) should ==([](1, 1, 2)) []("a", "b", "a", "b") removeFirst!("a", "x", "y") should ==([]("b", "a", "b")) - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:removeFirst!, 0)
takes one or two arguments, and will then use these arguments as code to decide what elements should be removed from the list. the method will return the receiver.
- - should change the list
[ show source ]
x = [](1, 2, 3) x removeIf!(>(1)) x should ==([](1))
- - should return the list
[ show source ]
x = [](1, 2, 3) x removeIf!(>(1)) should be same(x)
- - should take one code argument and apply that to all values
[ show source ]
[] removeIf!(>(1)) should ==([]) [](1, 2, 3) removeIf!(>(1)) should ==([](1)) [](1, 2, 3) removeIf!(true) should ==([]) [](nil, false, nil) removeIf!(nil?) should ==([](false)) [](nil, false, true) removeIf!(==(2)) should ==([](nil, false, true))
- - should take two arguments and use that as a predicate lexical block
[ show source ]
[] removeIf!(x, x >(1)) should ==([]) [](1, 2, 3) removeIf!(x, x >(1)) should ==([](1)) [](1, 2, 3) removeIf!(x, true) should ==([]) [](nil, false, nil) removeIf!(x, x nil?) should ==([](false)) [](nil, false, true) removeIf!(x, x ==(2)) should ==([](nil, false, true))
returns a list that contains all entries except for the first one, or the empty list if this list is empty.
[ show source ]
method(
if(empty?,
DefaultBehavior [],
[](1 ..(0 -(1)))))
- - should return an empty list for the empty list
[ show source ]
[] rest should ==([])
- - should return an empty list for a list with one entry
[ show source ]
[](1) rest should ==([]) [](2) rest should ==([]) []("foo") rest should ==([]) - - should return a list with the one element for a list with two entries
[ show source ]
[](1, 2) rest should ==([](2))
- - should return a list with the rest of the elements for a larger list
[ show source ]
[](1, 2, 3, 4, 5) rest should ==([](2, 3, 4, 5))
returns a new list that is a mimic of the current list, except that the order of all elements are reversed
[ show source ]
method( newList = self mimic newList reverse! newList)
- - should return the same list for an empty list
[ show source ]
[] reverse should ==([])
- - should return a reversed list
[ show source ]
[](1) reverse should ==([](1)) [](1, 2, 1) reverse should ==([](1, 2, 1)) [](1, 2, 3) reverse should ==([](3, 2, 1)) [](:foo, :bar) reverse should ==([](:bar, :foo))
- - should not modify the receiver
[ show source ]
x = [](1, 2, 3, 4) x reverse x should ==([](1, 2, 3, 4))
- - should not reverse internal lists
[ show source ]
[]([](1, 2), [](3, 4), [](5, 6), [](7, 8)) reverse should ==([]([](7, 8), [](5, 6), [](3, 4), [](1, 2)))
reverses the elements in this list, then returns it
- - should return the same list for an empty list
[ show source ]
[] reverse! should ==([])
- - should return a reversed list
[ show source ]
[](1) reverse! should ==([](1)) [](1, 2, 1) reverse! should ==([](1, 2, 1)) [](1, 2, 3) reverse! should ==([](3, 2, 1)) [](:foo, :bar) reverse! should ==([](:bar, :foo))
- - should modify the receiver
[ show source ]
x = [](1, 2, 3, 4) x reverse! x should ==([](4, 3, 2, 1))
- - should not reverse internal lists
[ show source ]
[]([](1, 2), [](3, 4), [](5, 6), [](7, 8)) reverse! should ==([]([](7, 8), [](5, 6), [](3, 4), [](1, 2)))
takes an object and returns the index of the last occurance of that object in this list, or nil if it doesn't exist
[ show source ]
method(obj,
((self size -(1)) ..(0)) each(index,
if(self [](index) ==(obj),
return(index)))
nil)
- - should return the first index backwards from the end where element == to object
[ show source ]
[](3, 2, 1, 1, 2, 3) rindex(3) should ==(5) [](3, 2, 1, 1, 2, 3) rindex(2) should ==(4) [](3, 2, 1, 1, 2, 3) rindex(1) should ==(3)
- - should return size-1 if last element == to object
[ show source ]
[](2, 1, 3, 2, 5) rindex(5) should ==(4)
- - should return 0 if only first element == to object
[ show source ]
[](2, 1, 3, 1, 5) rindex(2) should ==(0)
- - should return nil if no element == to object
[ show source ]
[](1, 1, 3, 2, 1, 3) rindex(4) should be nil
returns the second element of this list, or nil of the list has less than two entries
[ show source ]
method( [](1))
- - should return nil for an empty list
[ show source ]
[] second should be nil
- - should return nil for a list with one element
[ show source ]
[](33) second should be nil
- - should return the second element for a list with more than one element
[ show source ]
[](33, 45) second should ==(45)
returns a new sequence to iterate over this list
- - should return false when calling next? on a seq from an empty list
[ show source ]
[] seq next? should be false
- - should return a Sequence
[ show source ]
[](1) seq should mimic(Sequence)
- - should return an object that yields all objects in the list
[ show source ]
ss = [](42, 45, 6443) seq ss next should ==(42) ss next should ==(45) ss next should ==(6443) ss next? should be false
removes the first element from the list and returns it. returns nil if the list is empty.
- - should return nil for an empty list
[ show source ]
[] shift! should be nil
- - should return the element for a list with one element
[ show source ]
[](:blarg) shift! should ==(:blarg)
- - should remove the element in a list with one element
[ show source ]
l = [](:blarg) l shift! l should ==([])
- - should return the first element for a list with more than one element
[ show source ]
[](:blem, :flag, :moppy) shift! should ==(:blem)
- - should remove the first element in a list with more than one element
[ show source ]
l = [](:blem, :flag, :moppy) l shift! l should ==([](:flag, :moppy)) l shift! l should ==([](:moppy))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:shift!)
return a new list containing the same elements as the original list with their positions distributed randomly.
[ show source ]
method( pick(length))
- - should return a list of the same length
[ show source ]
l = [](:sam, :sooze, :beans) l shuffle length should ==(3)
- - should return a list containing the same elements
[ show source ]
l = [](:sam, :sooze, :beans) l sort should ==(l shuffle sort)
- - should not modify the original list
[ show source ]
l = (0 ..(100)) asList l shuffle l should ==((0 ..(100)) asList)
shuffles the list by randomly distributing the position of its elements
[ show source ]
method(
notPicked = self mimic
notPicked length times(index,
randomIndex = System randomNumber %(notPicked length)
[](index) = notPicked removeAt!(randomIndex))
self)
- - should not change the length of the list
[ show source ]
l = [](:sam, :sooze, :beans) l shuffle! l length should ==(3)
- - should not change the elements in the list
[ show source ]
l = [](:sam, :sooze, :beans) sorted = l sort l sort should ==(sorted)
- - should modify the list so that the elements are not in the same order (unless we're amazingly lucky/unlucky)
[ show source ]
(0 ..(1000)) asList shuffle! should not ==((0 ..(1000)) asList)
returns the size of this list
- - should return zero for an empty list
[ show source ]
x = [] x size should ==(0)
- - should return the size for a non-empty list
[ show source ]
[](1) size should ==(1) []("abc", "cde") size should ==(2) - - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:size)
returns a new sorted version of this list
- - should return a new, sorted list of numbers
[ show source ]
[](1, 2, 3) sort should ==([](1, 2, 3)) [](3, 2, 1) sort should ==([](1, 2, 3)) [](2, 3, 1) sort should ==([](1, 2, 3)) [](1, 3, 2) sort should ==([](1, 2, 3)) [](1, 3, 3, 3, 2, 2) sort should ==([](1, 2, 2, 3, 3, 3))
- - should return a new, sorted list of strings
[ show source ]
[]("foo", "bar", "quux") sort should ==([]("bar", "foo", "quux")) []("foo", "Bar", "bar", "quux") sort should ==([]("Bar", "bar", "foo", "quux")) - - should return a new, sorted list of symbols
[ show source ]
[](:foo, :bar, :quux) sort should ==([](:bar, :foo, :quux)) [](:foo, :Bar, :bar, :quux) sort should ==([](:Bar, :bar, :foo, :quux))
- - should sort based on '<=>
[ show source ]
Objs = Origin mimic x1 = Objs mimic x1 num = 42 x2 = Objs mimic x2 num = 32 x3 = Objs mimic x3 num = 52 Objs <=> = method(other, self num <=>(other num)) [](x1, x2, x3) sort should ==([](x2, x1, x3))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:sort)
sorts this list in place and then returns it
- - should return itself
[ show source ]
x = [] x sort! uniqueHexId should ==(x uniqueHexId)
- - should sort a list of numbers
[ show source ]
[](1, 2, 3) sort! should ==([](1, 2, 3)) [](3, 2, 1) sort! should ==([](1, 2, 3)) [](2, 3, 1) sort! should ==([](1, 2, 3)) [](1, 3, 2) sort! should ==([](1, 2, 3)) [](1, 3, 3, 3, 2, 2) sort! should ==([](1, 2, 2, 3, 3, 3))
- - should sort a list of strings
[ show source ]
[]("foo", "bar", "quux") sort! should ==([]("bar", "foo", "quux")) []("foo", "Bar", "bar", "quux") sort! should ==([]("Bar", "bar", "foo", "quux")) - - should sort a list of symbols
[ show source ]
[](:foo, :bar, :quux) sort! should ==([](:bar, :foo, :quux)) [](:foo, :Bar, :bar, :quux) sort! should ==([](:Bar, :bar, :foo, :quux))
- - should sort based on '<=>
[ show source ]
Objs = Origin mimic x1 = Objs mimic x1 num = 42 x2 = Objs mimic x2 num = 32 x3 = Objs mimic x3 num = 52 Objs <=> = method(other, self num <=>(other num)) [](x1, x2, x3) sort! should ==([](x2, x1, x3))
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:sort!)
returns the third element of this list, or nil of the list has less than three entries
[ show source ]
method( [](2))
- - should return nil for an empty list
[ show source ]
[] third should be nil
- - should return nil for a list with one element
[ show source ]
[](33) third should be nil
- - should return nil for a list with two elements
[ show source ]
[](33, 15) third should be nil
- - should return the third element for a list with more than two elements
[ show source ]
[](7, 25, 333) third should ==(333)
nil
- - should add an element to an empty list
[ show source ]
l = [] l unshift!(:foo) l should ==([](:foo))
- - should add an element at the beginning of a list with elements in it
[ show source ]
l = [](:foo, :bar, 1, 42) l unshift!(:flax) l should ==([](:flax, :foo, :bar, 1, 42))
- - should add an element several times if asked to
[ show source ]
l = [](:foo) l unshift!(:foo) l unshift!(:foo) l unshift!(:foo) l unshift!(:foo) l should ==([](:foo, :foo, :foo, :foo, :foo))
- - should return the list
[ show source ]
l = [] l unshift!(:foo) should ==(l)
- - should validate type of receiver
[ show source ]
List should checkReceiverTypeOn(:unshift!, 0)