| kind | = | "Mixins Enumerable" |
adds lots of helpful methods that can be done on enumerable methods. based on the 'each' method being available on the self.
- all?(...)
- any?(...)
- asList()
- asTuple()
- collect(...)
- collect:dict(...)
- collect:list(...)
- collect:set(...)
- collectFn(+blocks)
- collectFn:dict(+blocks)
- collectFn:set(+blocks)
- count(...)
- cycle(...)
- detect(...)
- drop(howMany)
- drop:dict(howMany)
- drop:set(howMany)
- dropWhile(...)
- dropWhile:dict(...)
- dropWhile:set(...)
- filter(...)
- filter:dict(...)
- filter:set(...)
- find(...)
- findAll(...)
- findAll:dict(...)
- findAll:set(...)
- findIndex(...)
- first(howMany nil)
- first:dict(howMany)
- first:set(howMany)
- flatMap(...)
- flatMap:dict(...)
- flatMap:list(...)
- flatMap:set(...)
- fold(...)
- grep(...)
- grep:set(...)
- group()
- groupBy(...)
- include?(toFind)
- inject(...)
- join(separator "")
- map(...)
- map:dict(...)
- map:list(...)
- map:set(...)
- mapFn(+blocks)
- mapFn:dict(+blocks)
- mapFn:set(+blocks)
- max(...)
- member?(toFind)
- min(...)
- none?(...)
- one?(...)
- partition(...)
- partition:dict(...)
- partition:set(...)
- reduce(...)
- reject(...)
- reject:dict(...)
- reject:set(...)
- select(...)
- select:dict(...)
- select:set(...)
- some(...)
- sort()
- sortBy(...)
- sum()
- take(howMany)
- take:dict(howMany)
- take:set(howMany)
- takeWhile(...)
- takeWhile:dict(...)
- takeWhile:set(...)
- zip(+listsAndFns)
- zip:set(+lists)
takes zero, one or two arguments. if zero arguments, returns false if any of the elements yielded by each is false, otherwise true. if one argument, expects it to be a message chain. if that message chain, when applied to the current element returns a false value, the method returns false. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns false for any element, this method returns false, otherwise true.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
self each(n,
x = cell(:n)
unless(cell(:x),
return(false)))
true,
argCount ==(
1),
theCode = call arguments [](
0)
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
unless(cell(:x),
return(false)))
true,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
unless(cell(:x),
return(false)))
true,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just check if all of the values are true
[ show source ]
[](1, 2, 3) all? should be true [](nil, false, nil) all? should be false [](nil, false, true) all? should be false CustomEnumerable all? should be true
- - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) all?(==(2)) should be false [](1, 2, 3) all?(>(0)) should be true [](nil, false, nil) all?(nil?) should be false [](nil, false, true) all?(==(2)) should be false CustomEnumerable all?(!=("foo")) should be true - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) all?(x, x ==(2)) should be false [](1, 2, 3) all?(x, x <(4)) should be true [](nil, false, nil) all?(x, x nil?) should be false [](nil, nil, nil) all?(x, x nil?) should be true [](nil, false, true) all?(x, x ==(2)) should be false CustomEnumerable all?(x, x !=("foo")) should be true
takes zero, one or two arguments. if zero arguments, returns true if any of the elements yielded by each is true, otherwise false. if one argument, expects it to be a message chain. if that message chain, when applied to the current element returns a true value, the method returns true. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns true for any element, this method returns true, otherwise false.
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
0),
self each(n,
x = cell(:n)
if(cell(:x),
return(true)))
false,
if(
argCount ==(
1),
theCode = call arguments [](
0)
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
return(true)))
false,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
return(true)))
false,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))))
)
- - should take zero arguments and just check if any of the values are true
[ show source ]
[](1, 2, 3) any? [](nil, false, nil) any? should be false [](nil, false, true) any? should be true CustomEnumerable any? should be true
- - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) any?(==(2)) should be true [](nil, false, nil) any?(nil?) should be true [](nil, false, true) any?(==(2)) should be false CustomEnumerable any?(!=("foo")) should be true - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) any?(x, x ==(2)) should be true [](nil, false, nil) any?(x, x nil?) should be true [](nil, false, true) any?(x, x ==(2)) should = = false CustomEnumerable any?(x, x !=("foo")) should be true
will return a list created from calling each on the receiver until everything has been yielded. if a more efficient version is possible of this, the object should implement it, since other Enumerable methods will use this for some operations. note that asList is not required to return a new list
[ show source ]
method( result = list self each(n, result <<(cell(:n))) result)
- - should return a list from a list
[ show source ]
[](1, 2, 3) asList should ==([](1, 2, 3))
- - should return a list based on all things yielded to each
[ show source ]
CustomEnumerable asList should ==([]("3first", "1second", "2third"))
will return a tuple created from calling each on the receiver until everything has been yielded.
[ show source ]
method( tuple(*(asList)))
- - should return a tuple from a list
[ show source ]
[](1, 2, 3) asTuple should ==(tuple(1, 2, 3))
- - should return a tuple based on all things yielded to each
[ show source ]
CustomEnumerable asTuple should ==(tuple("3first", "1second", "2third"))
nil
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
result <<(cell(:x)))
result,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
result <<(cell(:x)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))
)
- - should return an empty list for an empty enumerable
[ show source ]
[] collect(x, x +(2)) should ==([]) {} collect(x, x +(2)) should ==([]) set 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))
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x) kind ==("Pair"),
result [](x key) = x value,
result [](cell(:x)) = nil))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x) kind ==("Pair"),
result [](x key) = x value,
result [](cell(:x)) = nil))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return an empty dict for an empty enumerable
[ show source ]
[] collect:dict(x, x +(2)) should ==(dict) {} collect:dict(x, x +(2)) should ==(dict) set collect:dict(x, x +(2)) should ==(dict) - - should return the same dict for something that only returns itself
[ show source ]
[](1, 2, 3) collect:dict(x, x =>(x)) should ==(dict(1 =>(1), 2 =>(2), 3 =>(3)))
- - should take one argument and apply the inside
[ show source ]
[](1, 2, 3) collect:dict(=>(2)) should ==(dict(1 =>(2), 2 =>(2), 3 =>(2))) [](1, 2, 3) collect:dict(1 =>(1)) should ==(dict(1 =>(1)))
- - should take two arguments and apply the code with the argument name bound
[ show source ]
[](1, 2, 3) collect:dict(x, x =>(x +(3))) should ==(dict(1 =>(4), 2 =>(5), 3 =>(6))) [](1, 2, 3) collect:dict(x, x =>(1)) should ==(dict(1 =>(1), 2 =>(1), 3 =>(1))) [](1, 2, 3) collect:dict(x, x) should ==(dict(1 =>(nil), 2 =>(nil), 3 =>(nil)))
nil
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
result <<(cell(:x)))
result,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
result <<(cell(:x)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))
)
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
result <<(cell(:x)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
result <<(cell(:x)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return an empty set for an empty enumerable
[ show source ]
[] collect:set(x, x +(2)) should ==(set) {} collect:set(x, x +(2)) should ==(set) set collect:set(x, x +(2)) should ==(set) - - should return the same set for something that only returns itself
[ show source ]
[](1, 2, 3) collect:set(x, x) should ==(set(1, 2, 3))
- - should take one argument and apply the inside
[ show source ]
[](1, 2, 3) collect:set(+(2)) should ==(set(3, 4, 5)) [](1, 2, 3) collect:set(1) should ==(set(1))
- - should take two arguments and apply the code with the argument name bound
[ show source ]
[](1, 2, 3) collect:set(x, x +(3)) should ==(set(4, 5, 6)) [](1, 2, 3) collect:set(x, 1) should ==(set(1))
nil
[ show source ]
method(+blocks,
result = list
self each(n,
current = cell(:n)
blocks each(b, current = cell(:b) call(cell(:current)))
result <<(current))
result)
- - should take zero arguments and just return the elements in a list
[ show source ]
[](1, 2, 3) collectFn should ==([](1, 2, 3)) CustomEnumerable collectFn should ==([]("3first", "1second", "2third")) - - should take one lexical block argument and apply that to each element, and return the result in a list
[ show source ]
x = fn(arg, arg +(2)) [](1, 2, 3) collectFn(x) should ==([](3, 4, 5)) x = fn(arg, arg [](0 ..(2))) CustomEnumerable collectFn(x) should ==([]("3fi", "1se", "2th")) - - should take several lexical blocks and chain them together
[ show source ]
x = fn(arg, arg +(2)) x2 = fn(arg, arg *(2)) [](1, 2, 3) collectFn(x, x2) should ==([](6, 8, 10)) x = fn(arg, arg [](0 ..(2))) x2 = fn(arg, arg +("flurg")) CustomEnumerable collectFn(x, x2) should ==([]("3fiflurg", "1seflurg", "2thflurg"))
nil
[ show source ]
method(+blocks,
result = dict
self each(n,
current = cell(:n)
blocks each(b, current = cell(:b) call(cell(:current)))
if(cell(:current) mimics?(Pair),
result [](current key) = current value,
result [](cell(:current)) = nil)
)
result)
- - should take zero arguments and just return the elements in a dict
[ show source ]
[](1, 2, 3) collectFn:dict should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) CustomEnumerable collectFn:dict should ==({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil))) - - should take one lexical block argument and apply that to each element, and return the result in a dict
[ show source ]
x = fn(arg, arg =>(arg +(2))) [](1, 2, 3) collectFn:dict(x) should ==({}(1 =>(3), 2 =>(4), 3 =>(5))) x = fn(arg, arg [](0 ..(2)) =>(arg [](0 ..(0)))) CustomEnumerable collectFn:dict(x) should ==({}("3fi" =>("3"), "1se" =>("1"), "2th" =>("2"))) - - should take several lexical blocks and chain them together
[ show source ]
x = fn(arg, arg =>(arg +(2))) x2 = fn(arg, arg value =>(arg key)) [](1, 2, 3) collectFn:dict(x, x2) should ==({}(3 =>(1), 4 =>(2), 5 =>(3))) x = fn(arg, arg [](0 ..(2))) x2 = fn(arg, arg =>("flurg")) CustomEnumerable collectFn:dict(x, x2) should ==({}("3fi" =>("flurg"), "1se" =>("flurg"), "2th" =>("flurg")))
nil
[ show source ]
method(+blocks,
result = set
self each(n,
current = cell(:n)
blocks each(b, current = cell(:b) call(cell(:current)))
result <<(current))
result)
- - should take zero arguments and just return the elements in a set
[ show source ]
[](1, 2, 3) collectFn:set should ==(set(1, 2, 3)) CustomEnumerable collectFn:set should ==(set("3first", "1second", "2third")) - - should take one lexical block argument and apply that to each element, and return the result in a set
[ show source ]
x = fn(arg, arg +(2)) [](1, 2, 3) collectFn:set(x) should ==(set(3, 4, 5)) x = fn(arg, arg [](0 ..(2))) CustomEnumerable collectFn:set(x) should ==(set("3fi", "1se", "2th")) - - should take several lexical blocks and chain them together
[ show source ]
x = fn(arg, arg +(2)) x2 = fn(arg, arg *(2)) [](1, 2, 3) collectFn:set(x, x2) should ==(set(6, 8, 10)) x = fn(arg, arg [](0 ..(2))) x2 = fn(arg, arg +("flurg")) CustomEnumerable collectFn:set(x, x2) should ==(set("3fiflurg", "1seflurg", "2thflurg"))
takes zero, one or two arguments. if zero arguments, returns the number of elements in the collection. if one argument, expects it to be a message chain. if that message chain, that will be used as a predicate. returns the number of elements where the predicate returns true. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as a predicate, and the result will be the number of elements matching the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = 0
argLength = call arguments length
self each(n,
x = cell(:n)
if(cell(:x) ||(argLength ==(0)),
++(result)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = 0
argLength = call arguments length
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x) ||(argLength ==(0)),
++(result)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = 0
argLength = call arguments length
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x) ||(argLength ==(0)),
++(result)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return how many elements there are
[ show source ]
[](1, 2, 3) count should ==(3) [](nil, false) count should ==(2) [](nil, false, true) count should ==(3) CustomEnumerable count should ==(3)
- - should take one element that is a predicate, and return how many matches it
[ show source ]
[](1, 2, 3) count(>(1)) should ==(2) [](nil, false, nil) count(nil?) should ==(2) [](nil, false, true) count(==(2)) should ==(0) CustomEnumerable count([](0 ...(1)) !=("1")) should ==(2) - - should take two elements that turn into a lexical block and returns how many matches it
[ show source ]
[](1, 2, 3) count(x, x >(1)) should ==(2) [](nil, false, nil) count(x, x nil?) should ==(2) [](nil, false, true) count(x, x ==(2)) should ==(0) CustomEnumerable count(x, x !=("2third")) should ==(2)
takes one or two arguments and cycles over the elements of this collection. the cycling will be done by calling each once and collecting the result, and then using this to continue cycling. if one argument is given, it should be a message chain to apply. if two arguments are given, they will be turned into a lexical block and applied. if the collection is empty, returns nil.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
internal = list
self each(n,
internal <<(cell(:n))
theCode evaluateOn(call ground, cell(:n)))
if(internal empty?, return(nil))
loop(internal each(x, theCode evaluateOn(call ground, cell(:x)))),
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
internal = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
internal <<(cell(:n))
lexicalCode call(cell(:n)))
if(internal empty?, return(nil))
loop(internal each(x, lexicalCode call(cell(:x)))),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should not do anything for an empty collection
[ show source ]
x = 1 [] cycle(_, x = 2) should be nil x should ==(1)
- - should repeat until stopped
[ show source ]
Ground res = [] m1 = method( [](1, 2, 3) cycle(x, if(Ground res length ==(10), return) Ground res <<(x))) m1 Ground res should ==([](1, 2, 3, 1, 2, 3, 1, 2, 3, 1)) - - should only call each once
[ show source ]
CustomEnumerable3 = Origin mimic CustomEnumerable3 mimic!(Mixins Enumerable) CustomEnumerable3 eachCalled = 0 CustomEnumerable3 each = macro( ++(eachCalled) len = call arguments length if(len ==(1), first = call arguments first first evaluateOn(call ground, "3first") first evaluateOn(call ground, "1second") first evaluateOn(call ground, "2third"), lexical = LexicalBlock createFrom(call arguments, call ground) lexical call("3first") lexical call("1second") lexical call("2third"))) m = method( iter = 0 CustomEnumerable3 cycle(_, if(iter ==(10), return) ++(iter))) m CustomEnumerable3 eachCalled should ==(1) - - should take one argument and apply it
[ show source ]
Ground res = [] m1 = method( [](1, 2, 3) cycle(+(1) if(Ground res length ==(10), return) Ground res <<("foo"))) m1 - - should take two arguments and turn it into a lexical block to apply
[ show source ]
Ground res = [] m1 = method( [](1, 2, 3) cycle(x, if(Ground res length ==(10), return) Ground res <<(x))) m1 Ground res should ==([](1, 2, 3, 1, 2, 3, 1, 2, 3, 1))
nil
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
0),
self each(n,
x = cell(:n)
if(cell(:x),
return(cell(:n))))
nil,
if(
argCount ==(
1),
theCode = call arguments [](
0)
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
return(cell(:n))))
nil,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
return(cell(:n))))
nil,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))))
)
- - should take zero arguments and just check if any of the values are true, and then return it
[ show source ]
[](1, 2, 3) detect should ==(1) [](nil, false, nil) detect should be nil [](nil, false, true) detect should be true CustomEnumerable detect should ==("3first") - - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) detect(==(2)) should ==(2) [](nil, false, nil) detect(nil?) should be nil [](nil, false, true) detect(==(2)) should be nil CustomEnumerable detect(!=("foo")) should ==("3first") - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) detect(x, x ==(2)) should ==(2) [](nil, false, nil) detect(x, x nil?) should be nil [](nil, false, true) detect(x, x ==(2)) should be nil CustomEnumerable detect(x, x !=("foo")) should ==("3first")
takes one argument and returns a list of all the elements in this object except for how many that should be avoided.
[ show source ]
method(howMany,
result = list
currentCount = howMany
self each(n,
if(currentCount >(0),
--(currentCount),
result <<(cell(:n))))
result)
- - should return a list without as many elements as requested
[ show source ]
[](1, 2, 3) drop(0) should ==([](1, 2, 3)) [](1, 2, 3) drop(1) should ==([](2, 3)) [](1, 2, 3) drop(2) should ==([](3)) [](1, 2, 3) drop(3) should ==([]) CustomEnumerable drop(2) should ==([]("2third")) - - should not drop more elements than the length of the collection
[ show source ]
[](1, 2, 3) drop(4) should ==([]) [](1, 2, 3) drop(10) should ==([]) CustomEnumerable drop(200) should ==([])
takes one argument and returns a dict of all the elements in this object except for how many that should be avoided.
[ show source ]
method(howMany,
result = dict
currentCount = howMany
self each(n,
if(currentCount >(0),
--(currentCount),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result)
- - should return a dict without as many elements as requested
[ show source ]
[](1, 2, 3) drop:dict(0) should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) [](1, 2, 3) drop:dict(1) should ==({}(2 =>(nil), 3 =>(nil))) [](1, 2, 3) drop:dict(2) should ==({}(3 =>(nil))) [](1, 2, 3) drop:dict(3) should ==({}) [](:foo =>(42), :bar =>(55), :quux =>(2323)) drop:dict(0) should ==({}(:foo =>(42), :bar =>(55), :quux =>(2323))) [](:foo =>(42), :bar =>(55), :quux =>(2323)) drop:dict(1) should ==({}(:bar =>(55), :quux =>(2323))) [](:foo =>(42), :bar =>(55), :quux =>(2323)) drop:dict(2) should ==({}(:quux =>(2323))) CustomEnumerable drop:dict(2) should ==({}("2third" =>(nil))) - - should not drop more elements than the length of the collection
[ show source ]
[](1, 2, 3) drop:dict(4) should ==({}) [](1, 2, 3) drop:dict(10) should ==({}) CustomEnumerable drop:dict(200) should ==({})
takes one argument and returns a set of all the elements in this object except for how many that should be avoided.
[ show source ]
method(howMany,
result = set
currentCount = howMany
self each(n,
if(currentCount >(0),
--(currentCount),
result <<(cell(:n))))
result)
- - should return a set without as many elements as requested
[ show source ]
[](1, 2, 3) drop:set(0) should ==(set(1, 2, 3)) [](1, 2, 3) drop:set(1) should ==(set(2, 3)) [](1, 2, 3) drop:set(2) should ==(set(3)) [](1, 2, 3) drop:set(3) should ==(set) CustomEnumerable drop:set(2) should ==(set("2third")) - - should not drop more elements than the length of the collection
[ show source ]
[](1, 2, 3) drop:set(4) should ==(set) [](1, 2, 3) drop:set(10) should ==(set) CustomEnumerable drop:set(200) should ==(set)
takes zero, one or two arguments. it will evaluate a predicate once for each element, and avoid all the elements until the predicate returns false for the first time, then it will start collecting data. if zero arguments, the predicate is the element itself. if one argument, expects it to be a message chain to apply as a predicate. if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = list
collecting = false
self each(n,
x = cell(:n)
if(collecting,
result <<(cell(:n)),
unless(cell(:x),
collecting = true
result <<(cell(:n)))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = list
collecting = false
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(collecting,
result <<(cell(:n)),
unless(cell(:x),
collecting = true
result <<(cell(:n)))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
collecting = false
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(collecting,
result <<(cell(:n)),
unless(cell(:x),
collecting = true
result <<(cell(:n)))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return everything after the point where a value is true
[ show source ]
[](1, 2, 3) dropWhile should ==([]) [](1, 2, nil, false) dropWhile should ==([](nil, false)) [](1, 2, false, 3, 4, nil, false) dropWhile should ==([](false, 3, 4, nil, false)) CustomEnumerable dropWhile should ==([])
- - should take one argument and apply it as a message chain, return a list with all elements after the block returns false
[ show source ]
[](1, 2, 3) dropWhile(<(3)) should ==([](3)) [](1, 2, 3) dropWhile(!=(2)) should ==([](2, 3)) CustomEnumerable dropWhile(!=("2third")) should ==([]("2third")) - - should take two arguments and apply the lexical block created from it, and return a list with all elements after the block returns false
[ show source ]
[](1, 2, 3) dropWhile(x, x <(3)) should ==([](3)) [](1, 2, 3) dropWhile(x, x !=(2)) should ==([](2, 3)) CustomEnumerable dropWhile(x, x !=("2third")) should ==([]("2third"))
takes zero, one or two arguments. it will evaluate a predicate once for each element, and avoid all the elements until the predicate returns false for the first time, then it will start collecting data. if zero arguments, the predicate is the element itself. if one argument, expects it to be a message chain to apply as a predicate. if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
collecting = false
self each(n,
x = cell(:n)
if(collecting,
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil),
unless(cell(:x),
collecting = true
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
collecting = false
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(collecting,
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil),
unless(cell(:x),
collecting = true
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
collecting = false
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(collecting,
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil),
unless(cell(:x),
collecting = true
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return everything after the point where a value is true
[ show source ]
[](1, 2, 3) dropWhile:dict should ==({}) [](1, 2, nil, false) dropWhile:dict should ==({}(nil =>(nil), false =>(nil))) [](1, 2, false, 3, 4, nil, false) dropWhile:dict should ==({}(false =>(nil), 3 =>(nil), 4 =>(nil), nil =>(nil))) [](:foo =>(42), :bar =>(55), :quux =>(1242)) takeWhile:dict should ==({}(foo: 42, bar: 55, quux: 1242)) CustomEnumerable dropWhile:dict should ==({}) - - should take one argument and apply it as a message chain, return a dict with all elements after the block returns false
[ show source ]
[](1, 2, 3) dropWhile:dict(<(3)) should ==({}(3 =>(nil))) [](1, 2, 3) dropWhile:dict(!=(2)) should ==({}(2 =>(nil), 3 =>(nil))) [](:foo =>(42), :bar =>(55), :quux =>(1242)) dropWhile:dict(value <(56)) should ==({}(quux: 1242)) CustomEnumerable dropWhile:dict(!=("2third")) should ==({}("2third" =>(nil))) - - should take two arguments and apply the lexical block created from it, and return a dict with all elements after the block returns false
[ show source ]
[](1, 2, 3) dropWhile:dict(x, x <(3)) should ==({}(3 =>(nil))) [](1, 2, 3) dropWhile:dict(x, x !=(2)) should ==({}(2 =>(nil), 3 =>(nil))) [](:foo =>(42), :bar =>(55), :quux =>(1242)) dropWhile:dict(x, x value <(56)) should ==({}(quux: 1242)) CustomEnumerable dropWhile:dict(x, x !=("2third")) should ==({}("2third" =>(nil)))
takes zero, one or two arguments. it will evaluate a predicate once for each element, and avoid all the elements until the predicate returns false for the first time, then it will start collecting data. if zero arguments, the predicate is the element itself. if one argument, expects it to be a message chain to apply as a predicate. if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = set
collecting = false
self each(n,
x = cell(:n)
if(collecting,
result <<(cell(:n)),
unless(cell(:x),
collecting = true
result <<(cell(:n)))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = set
collecting = false
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(collecting,
result <<(cell(:n)),
unless(cell(:x),
collecting = true
result <<(cell(:n)))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
collecting = false
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(collecting,
result <<(cell(:n)),
unless(cell(:x),
collecting = true
result <<(cell(:n)))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return everything after the point where a value is true
[ show source ]
[](1, 2, 3) dropWhile:set should ==(set) [](1, 2, nil, false) dropWhile:set should ==(set(nil, false)) [](1, 2, false, 3, 4, nil, false) dropWhile:set should ==(set(false, 3, 4, nil)) CustomEnumerable dropWhile:set should ==(set)
- - should take one argument and apply it as a message chain, return a set with all elements after the block returns false
[ show source ]
[](1, 2, 3) dropWhile:set(<(3)) should ==(set(3)) [](1, 2, 3) dropWhile:set(!=(2)) should ==(set(2, 3)) CustomEnumerable dropWhile:set(!=("2third")) should ==(set("2third")) - - should take two arguments and apply the lexical block created from it, and return a set with all elements after the block returns false
[ show source ]
[](1, 2, 3) dropWhile:set(x, x <(3)) should ==(set(3)) [](1, 2, 3) dropWhile:set(x, x !=(2)) should ==(set(2, 3)) CustomEnumerable dropWhile:set(x, x !=("2third")) should ==(set("2third"))
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = list
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a list with only the true values
[ show source ]
[](1, 2, 3) filter should ==([](1, 2, 3)) [](nil, false, nil) filter should ==([]) [](nil, false, true) filter should ==([](true)) CustomEnumerable filter should ==(CustomEnumerable asList)
- - should take one argument that ends up being a predicate and return a list of the values that is true
[ show source ]
[](1, 2, 3) filter(>(1)) should ==([](2, 3)) [](nil, false, nil) filter(nil?) should ==([](nil, nil)) [](nil, false, true) filter(==(2)) should ==([]) CustomEnumerable filter([](0 ...(1)) !=("1")) should ==([]("3first", "2third")) - - should take two arguments that ends up being a predicate and return a list of the values that is true
[ show source ]
[](1, 2, 3) filter(x, x >(1)) should ==([](2, 3)) [](nil, false, nil) filter(x, x nil?) should ==([](nil, nil)) [](nil, false, true) filter(x, x ==(2)) should ==([]) CustomEnumerable filter(x, x !=("2third")) should ==([]("3first", "1second"))
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
self each(n,
x = cell(:n)
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a dict with only the true values
[ show source ]
[](1, 2, 3) filter:dict should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) [](nil, false, nil) filter:dict should ==({}) [](nil, false, true) filter:dict should ==({}(true =>(nil))) {}(nil =>(42), true =>(55), blah: 222) filter:dict should ==({}(nil =>(42), true =>(55), blah: 222)) CustomEnumerable filter:dict should ==({}("3first" =>(nil), "2third" =>(nil), "1second" =>(nil))) - - should take one argument that ends up being a predicate and return a dict of the values that is true
[ show source ]
[](1, 2, 3) filter:dict(>(1)) should ==({}(2 =>(nil), 3 =>(nil))) [](nil, false, nil) filter:dict(nil?) should ==({}(nil =>(nil))) [](nil, false, true) filter:dict(==(2)) should ==({}) {}(foo: 42, bar: 2324, quux: 42) filter:dict(value ==(42)) should ==({}(foo: 42, quux: 42)) CustomEnumerable filter:dict([](0 ...(1)) !=("1")) should ==({}("3first" =>(nil), "2third" =>(nil))) - - should take two arguments that ends up being a predicate and return a dict of the values that is true
[ show source ]
[](1, 2, 3) filter:dict(x, x >(1)) should ==({}(2 =>(nil), 3 =>(nil))) [](nil, false, nil) filter:dict(x, x nil?) should ==({}(nil =>(nil))) [](nil, false, true) filter:dict(x, x ==(2)) should ==({}) {}(foo: 42, bar: 2324, quux: 42) filter:dict(x, x value ==(42)) should ==({}(foo: 42, quux: 42)) CustomEnumerable filter:dict(x, x !=("2third")) should ==({}("3first" =>(nil), "1second" =>(nil)))
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = set
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a set with only the true values
[ show source ]
[](1, 2, 3) filter:set should ==(set(1, 2, 3)) [](nil, false, nil) filter:set should ==(set) [](nil, false, true) filter:set should ==(set(true)) CustomEnumerable filter:set should ==(set(*(CustomEnumerable asList)))
- - should take one argument that ends up being a predicate and return a set of the values that is true
[ show source ]
[](1, 2, 3) filter:set(>(1)) should ==(set(2, 3)) [](nil, false, nil) filter:set(nil?) should ==(set(nil)) [](nil, false, true) filter:set(==(2)) should ==(set) CustomEnumerable filter:set([](0 ...(1)) !=("1")) should ==(set("3first", "2third")) - - should take two arguments that ends up being a predicate and return a set of the values that is true
[ show source ]
[](1, 2, 3) filter:set(x, x >(1)) should ==(set(2, 3)) [](nil, false, nil) filter:set(x, x nil?) should ==(set(nil)) [](nil, false, true) filter:set(x, x ==(2)) should ==(set) CustomEnumerable filter:set(x, x !=("2third")) should ==(set("3first", "1second"))
takes zero, one or two arguments. if zero arguments, returns the first element that is true, otherwise nil. if one argument, expects it to be a message chain. if that message chain, when applied to the current element returns a true value, the corresponding element is returned. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns true for any element, the element will be retuend, otherwise nil.
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
0),
self each(n,
x = cell(:n)
if(cell(:x),
return(cell(:n))))
nil,
if(
argCount ==(
1),
theCode = call arguments [](
0)
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
return(cell(:n))))
nil,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
return(cell(:n))))
nil,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))))
)
- - should take zero arguments and just check if any of the values are true, and then return it
[ show source ]
[](1, 2, 3) find should ==(1) [](nil, false, nil) find should be nil [](nil, false, true) find should be true CustomEnumerable find should ==("3first") - - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) find(==(2)) should ==(2) [](nil, false, nil) find(nil?) should be nil [](nil, false, true) find(==(2)) should be nil CustomEnumerable find(!=("foo")) should ==("3first") - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) find(x, x ==(2)) should ==(2) [](nil, false, nil) find(x, x nil?) should be nil [](nil, false, true) find(x, x ==(2)) should be nil CustomEnumerable find(x, x !=("foo")) should ==("3first")
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = list
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a list with only the true values
[ show source ]
[](1, 2, 3) findAll should ==([](1, 2, 3)) [](nil, false, nil) findAll should ==([]) [](nil, false, true) findAll should ==([](true)) CustomEnumerable findAll should ==(CustomEnumerable asList)
- - should take one argument that ends up being a predicate and return a list of the values that is true
[ show source ]
[](1, 2, 3) findAll(>(1)) should ==([](2, 3)) [](nil, false, nil) findAll(nil?) should ==([](nil, nil)) [](nil, false, true) findAll(==(2)) should ==([]) CustomEnumerable findAll([](0 ...(1)) !=("1")) should ==([]("3first", "2third")) - - should take two arguments that ends up being a predicate and return a list of the values that is true
[ show source ]
[](1, 2, 3) findAll(x, x >(1)) should ==([](2, 3)) [](nil, false, nil) findAll(x, x nil?) should ==([](nil, nil)) [](nil, false, true) findAll(x, x ==(2)) should ==([]) CustomEnumerable findAll(x, x !=("2third")) should ==([]("3first", "1second"))
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
self each(n,
x = cell(:n)
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a dict with only the true values
[ show source ]
[](1, 2, 3) findAll:dict should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) [](nil, false, nil) findAll:dict should ==({}) [](nil, false, true) findAll:dict should ==({}(true =>(nil))) {}(nil =>(42), true =>(55), blah: 222) findAll:dict should ==({}(nil =>(42), true =>(55), blah: 222)) CustomEnumerable findAll:dict should ==({}("3first" =>(nil), "2third" =>(nil), "1second" =>(nil))) - - should take one argument that ends up being a predicate and return a dict of the values that is true
[ show source ]
[](1, 2, 3) findAll:dict(>(1)) should ==({}(2 =>(nil), 3 =>(nil))) [](nil, false, nil) findAll:dict(nil?) should ==({}(nil =>(nil))) [](nil, false, true) findAll:dict(==(2)) should ==({}) {}(foo: 42, bar: 2324, quux: 42) findAll:dict(value ==(42)) should ==({}(foo: 42, quux: 42)) CustomEnumerable findAll:dict([](0 ...(1)) !=("1")) should ==({}("3first" =>(nil), "2third" =>(nil))) - - should take two arguments that ends up being a predicate and return a dict of the values that is true
[ show source ]
[](1, 2, 3) findAll:dict(x, x >(1)) should ==({}(2 =>(nil), 3 =>(nil))) [](nil, false, nil) findAll:dict(x, x nil?) should ==({}(nil =>(nil))) [](nil, false, true) findAll:dict(x, x ==(2)) should ==({}) {}(foo: 42, bar: 2324, quux: 42) findAll:dict(x, x value ==(42)) should ==({}(foo: 42, quux: 42)) CustomEnumerable findAll:dict(x, x !=("2third")) should ==({}("3first" =>(nil), "1second" =>(nil)))
nil
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = set
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a set with only the true values
[ show source ]
[](1, 2, 3) findAll:set should ==(set(1, 2, 3)) [](nil, false, nil) findAll:set should ==(set) [](nil, false, true) findAll:set should ==(set(true)) CustomEnumerable findAll:set should ==(set(*(CustomEnumerable asList)))
- - should take one argument that ends up being a predicate and return a set of the values that is true
[ show source ]
[](1, 2, 3) findAll:set(>(1)) should ==(set(2, 3)) [](nil, false, nil) findAll:set(nil?) should ==(set(nil)) [](nil, false, true) findAll:set(==(2)) should ==(set) CustomEnumerable findAll:set([](0 ...(1)) !=("1")) should ==(set("3first", "2third")) - - should take two arguments that ends up being a predicate and return a set of the values that is true
[ show source ]
[](1, 2, 3) findAll:set(x, x >(1)) should ==(set(2, 3)) [](nil, false, nil) findAll:set(x, x nil?) should ==(set(nil)) [](nil, false, true) findAll:set(x, x ==(2)) should ==(set) CustomEnumerable findAll:set(x, x !=("2third")) should ==(set("3first", "1second"))
takes zero, one or two arguments. if zero arguments, returns the index of the first element that is true, otherwise nil. if one argument, expects it to be a message chain. if that message chain, when applied to the current element returns a true value, the corresponding element index is returned. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns true for any element, the element index will be returned, otherwise nil.
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
0),
self each(ix, n, if(cell(:n), return(ix)))
nil,
if(
argCount ==(
1),
theCode = call arguments [](
0)
self each(ix, n, if(theCode evaluateOn(call ground, cell(:n)), return(ix)))
nil,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(ix, n, if(lexicalCode call(cell(:n)), return(ix)))
nil,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))))
)
- - should take zero arguments and just check if any of the values are true, and then return the index of it
[ show source ]
[](1, 2, 3) findIndex should ==(0) [](nil, false, nil) findIndex should be nil [](nil, false, true) findIndex should ==(2) CustomEnumerable findIndex should ==(0)
- - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) findIndex(==(2)) should ==(1) [](nil, false, nil) findIndex(nil?) should ==(0) [](nil, false, true) findIndex(==(2)) should be nil CustomEnumerable findIndex(!=("foo")) should ==(0) - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) findIndex(x, x ==(2)) should ==(1) [](nil, false, nil) findIndex(x, x nil?) should ==(0) [](nil, false, true) findIndex(x, x ==(2)) should be nil CustomEnumerable findIndex(x, x !=("foo")) should ==(0)
takes one optional argument. if no argument is given, first will return the first element in the collection, or nil if no such element exists. if an argument is given, it should be a number describing how many elements to get. the return value will be a list in that case
[ show source ]
method(howMany nil,
if(howMany,
result = list
self each(n,
if(howMany ==(0), return(result))
--(howMany)
result <<(cell(:n)))
return(result),
self each(n, return(cell(:n)))
return(nil)))
- - should return nil for an empty collection
[ show source ]
set first should be nil
- - should take an optional argument of how many to return
[ show source ]
set first(0) should ==([]) set first(1) should ==([]) set first(2) should ==([])
- - should return the first element for a non-empty collection
[ show source ]
set(42) first should ==(42) CustomEnumerable first should ==("3first") - - should return the first n elements for a non-empty collection
[ show source ]
set(42) first(0) should ==([]) set(42) first(1) should ==([](42)) set(42) first(2) should ==([](42)) [](42, 44, 46) first(2) should ==([](42, 44)) set(42, 44, 46) first(3) sort should ==([](42, 44, 46)) CustomEnumerable first(2) should ==([]("3first", "1second"))
takes one argument. the argument should be a number describing how many elements to get. the return value will be a dict
[ show source ]
method(howMany,
result = dict
self each(n,
if(howMany ==(0), return(result))
--(howMany)
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil))
return(result))
- - should take an argument of how many to return
[ show source ]
set first:dict(0) should ==({}) set first:dict(1) should ==({}) set first:dict(2) should ==({}) - - should return the first n elements for a non-empty collection
[ show source ]
set(42) first:dict(0) should ==({}) set(42) first:dict(1) should ==({}(42 =>(nil))) set(42) first:dict(2) should ==({}(42 =>(nil))) [](42, 44, 46) first:dict(2) should ==({}(42 =>(nil), 44 =>(nil))) set(42, 44, 46) first:dict(3) should ==({}(42 =>(nil), 44 =>(nil), 46 =>(nil))) {}(foo: 42, bar: 66) first:dict(0) should ==({}) {}(foo: 42, bar: 66) first:dict(2) should ==({}(foo: 42, bar: 66)) {}(foo: 42, bar: 66) first:dict(3) should ==({}(foo: 42, bar: 66)) CustomEnumerable first:dict(2) should ==({}("3first" =>(nil), "1second" =>(nil)))
takes one argument. the argument should be a number describing how many elements to get. the return value will be a set
[ show source ]
method(howMany,
result = set
self each(n,
if(howMany ==(0), return(result))
--(howMany)
result <<(cell(:n)))
return(result))
- - should take an argument of how many to return
[ show source ]
set first:set(0) should ==(set) set first:set(1) should ==(set) set first:set(2) should ==(set)
- - should return the first n elements for a non-empty collection
[ show source ]
set(42) first:set(0) should ==(set) set(42) first:set(1) should ==(set(42)) set(42) first:set(2) should ==(set(42)) [](42, 44, 46) first:set(2) should ==(set(42, 44)) set(42, 44, 46) first:set(3) should ==(set(42, 44, 46)) CustomEnumerable first:set(2) should ==(set("3first", "1second"))
expects to get the same kind of arguments as map, and that each map operation returns a list. these lists will then be folded into a single list.
[ show source ]
macro(
call resendToMethod("map") fold(+))
- - should return a correct flattened list
[ show source ]
[](1, 2, 3) flatMap(x, [](x)) should ==([](1, 2, 3)) [](1, 2, 3) flatMap(x, [](x, x +(10), x +(20))) should ==([](1, 11, 21, 2, 12, 22, 3, 13, 23)) [](4, 5, 6) flatMap(x, [](x +(20), x +(10), x)) should ==([](24, 14, 4, 25, 15, 5, 26, 16, 6))
expects to get the same kind of arguments as map:dict, and that each map operation returns a dict for key. these dicts will then be folded into a single dict.
[ show source ]
macro(
call resendToMethod("map:dict") fold({}, sum, arg,
arg key each(val,
sum [](val key) = val value)
sum)
)
- - should return a correct flattened dict
[ show source ]
[](1, 2, 3) flatMap:dict(x, dict(x =>(x +(2)))) should ==(dict(1 =>(3), 2 =>(4), 3 =>(5))) [](1, 2, 3) flatMap:dict(x, dict(x =>(nil), (x +(10)) =>(nil), (x +(20)) =>(nil))) should ==(dict(1 =>(nil), 11 =>(nil), 21 =>(nil), 2 =>(nil), 12 =>(nil), 22 =>(nil), 3 =>(nil), 13 =>(nil), 23 =>(nil))) [](4, 5, 6) flatMap:dict(x, dict((x +(20)) =>(nil), (x +(10)) =>(nil), x =>(nil))) should ==(dict(24 =>(nil), 14 =>(nil), 4 =>(nil), 25 =>(nil), 15 =>(nil), 5 =>(nil), 26 =>(nil), 16 =>(nil), 6 =>(nil)))
expects to get the same kind of arguments as map:set, and that each map operation returns a set. these sets will then be folded into a single set.
[ show source ]
macro(
call resendToMethod("map:set") fold(+))
- - should return a correct flattened set
[ show source ]
[](1, 2, 3) flatMap:set(x, set(x)) should ==(set(1, 2, 3)) [](1, 2, 3) flatMap:set(x, set(x, x +(10), x +(20))) should ==(set(1, 11, 21, 2, 12, 22, 3, 13, 23)) [](4, 5, 6) flatMap:set(x, set(x +(20), x +(10), x)) should ==(set(24, 14, 4, 25, 15, 5, 26, 16, 6))
nil
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
theCode = theCode deepCopy
elementName = genSym
theCode last <<(message(elementName))
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
call ground cell(elementName) = cell(:n)
sum = theCode evaluateOn(call ground, cell(:sum))))
return(cell(:sum)),
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
elementName = argName name
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
call ground cell(elementName) = cell(:n)
sum = theCode evaluateOn(call ground, cell(:sum))))
return(cell(:sum)),
if(
argCount ==(
3),
sumArgName = call arguments [](
0)
argName = call arguments [](
1)
theCode = call arguments [](
2)
lexicalCode = LexicalBlock createFrom(list(sumArgName, argName, theCode), call ground)
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
sum = lexicalCode call(cell(:sum), cell(:n))))
return(cell(:sum)),
if(
argCount ==(
4),
sum = call argAt(
0)
sumArgName = call arguments [](
1)
argName = call arguments [](
2)
theCode = call arguments [](
3)
lexicalCode = LexicalBlock createFrom(list(sumArgName, argName, theCode), call ground)
self each(n,
sum = lexicalCode call(cell(:sum), cell(:n)))
return(cell(:sum)),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))))
)
- - should take one argument that is a message chain and apply that on the sum, with the current arg as argument
[ show source ]
[](1, 2, 3) fold(+) should ==(6) [](1, 2, 3) fold(*(5) -) should ==(12) CustomEnumerable2 fold(-) should ==(9)
- - should take two arguments that is an argument name and a message chain and apply that on the sum
[ show source ]
[](1, 2, 3) fold(x, +(x *(2))) should ==(11) [](1, 2, 3) fold(x, *(5) -(x)) should ==(12) CustomEnumerable2 fold(x, -(x)) should ==(9)
- - should take three arguments that is the sum name, the argument name and code to apply
[ show source ]
[](1, 2, 3) fold(sum, x, sum +(x *(2))) should ==(11) [](1, 2, 3) fold(sum, x, sum *(5) -(x)) should ==(12) CustomEnumerable2 fold(sum, x, sum -(x)) should ==(9)
- - should take four arguments that is the initial value, the sum name, the argument name and code to apply
[ show source ]
[](1, 2, 3) fold(13, sum, x, sum +(x *(2))) should ==(25) [](1, 2, 3) fold(1, sum, x, sum *(5) -(x)) should ==(87) CustomEnumerable2 fold(100, sum, x, sum -(x)) should ==(25)
takes one, two or three arguments. grep will first find any elements in the collection matching the first argument with '==='. if two or three arguments are given, these will be used to transform the matching object and then add the transformed version instead of the original element to the result list. the two argument version expects the second argument to be a message chain, and the three argument version expects it to be something that can be turned into a lexical block
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
matchingAgainst = call argAt(
0)
result = list
self each(n,
if(matchingAgainst ===(cell(:n)),
result <<(cell(:n))))
result,
argCount ==(
2),
matchingAgainst = call argAt(
0)
theCode = call arguments [](
1)
result = list
self each(n,
if(matchingAgainst ===(cell(:n)),
result <<(theCode evaluateOn(call ground, cell(:n)))))
result,
argCount ==(
3),
matchingAgainst = call argAt(
0)
argName = call arguments [](
1)
theCode = call arguments [](
2)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
if(matchingAgainst ===(cell(:n)),
result <<(lexicalCode call(cell(:n)))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take one argument and return everything that matches with ===
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9) grep(2 ..(5)) should ==([](2, 3, 4, 5)) customObj = Origin mimic customObj === = method(other, (other <(3)) ||(other >(5))) [](1, 2, 3, 4, 5, 6, 7, 8, 9) grep(customObj) should ==([](1, 2, 6, 7, 8, 9))
- - should take two arguments where the second argument is a message chain and return the result of calling that chain on everything that matches with ===
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9) grep(2 ..(5), +(1)) should ==([](3, 4, 5, 6)) customObj = Origin mimic customObj === = method(other, (other <(3)) ||(other >(5))) [](1, 2, 3, 4, 5, 6, 7, 8, 9) grep(customObj, +(1)) should ==([](2, 3, 7, 8, 9, 10))
- - should take three arguments where the second and third arguments gets turned into a lexical block to apply to all that matches with ===
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9) grep(2 ..(5), x, (x +(1)) asText) should ==([]("3", "4", "5", "6")) customObj = Origin mimic customObj === = method(other, (other <(3)) ||(other >(5))) [](1, 2, 3, 4, 5, 6, 7, 8, 9) grep(customObj, x, (x +(1)) asText) should ==([]("2", "3", "7", "8", "9", "10"))
takes one, two or three arguments. grep will first find any elements in the collection matching the first argument with '==='. if two or three arguments are given, these will be used to transform the matching object and then add the transformed version instead of the original element to the result set. the two argument version expects the second argument to be a message chain, and the three argument version expects it to be something that can be turned into a lexical block
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
matchingAgainst = call argAt(
0)
result = set
self each(n,
if(matchingAgainst ===(cell(:n)),
result <<(cell(:n))))
result,
argCount ==(
2),
matchingAgainst = call argAt(
0)
theCode = call arguments [](
1)
result = set
self each(n,
if(matchingAgainst ===(cell(:n)),
result <<(theCode evaluateOn(call ground, cell(:n)))))
result,
argCount ==(
3),
matchingAgainst = call argAt(
0)
argName = call arguments [](
1)
theCode = call arguments [](
2)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
if(matchingAgainst ===(cell(:n)),
result <<(lexicalCode call(cell(:n)))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take one argument and return everything that matches with ===
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9) grep:set(2 ..(5)) should ==(set(2, 3, 4, 5)) customObj = Origin mimic customObj === = method(other, (other <(3)) ||(other >(5))) [](1, 2, 3, 4, 5, 6, 7, 8, 9) grep:set(customObj) should ==(set(1, 2, 6, 7, 8, 9))
- - should take two arguments where the second argument is a message chain and return the result of calling that chain on everything that matches with ===
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9) grep:set(2 ..(5), +(1)) should ==(set(3, 4, 5, 6)) customObj = Origin mimic customObj === = method(other, (other <(3)) ||(other >(5))) [](1, 2, 3, 4, 5, 6, 7, 8, 9) grep:set(customObj, +(1)) should ==(set(2, 3, 7, 8, 9, 10))
- - should take three arguments where the second and third arguments gets turned into a lexical block to apply to all that matches with ===
[ show source ]
[](1, 2, 3, 4, 5, 6, 7, 8, 9) grep:set(2 ..(5), x, (x +(1)) asText) should ==(set("3", "4", "5", "6")) customObj = Origin mimic customObj === = method(other, (other <(3)) ||(other >(5))) [](1, 2, 3, 4, 5, 6, 7, 8, 9) grep:set(customObj, x, (x +(1)) asText) should ==(set("2", "3", "7", "8", "9", "10"))
returns a dict where all the keys are distinct elements in the enumerable, and each value is a list of all the values that are equivalent
[ show source ]
method( groupBy)
- - should return an empty dict for an empty enumerable
[ show source ]
[] group should ==({}) (1 ...(1)) group should ==({}) set group should ==({}) - - should return a dict with all distinct values as keys
[ show source ]
[](:abc, :cde :foo, :cde) group keys should ==(set(:abc, :cde, :foo))
- - should group all the same values into a list
[ show source ]
[](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) group should ==({}(1 =>([](1)), 2 =>([](2, 2)), 3 =>([](3, 3, 3)), 5 =>([](5, 5, 5, 5, 5)))) {}(foo: 42, bar: 55) group should ==({}((:foo =>(42)) =>([](:foo =>(42))), (:bar =>(55)) =>([](:bar =>(55)))))
takes zero, one or two arguments. it will evaluate all the elements in the enumerable and return a dictionary where the keys will be the result of evaluating the arguments and the value will be a list of all the original values that match that key.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
self each(n,
x = cell(:n)
if(result key?(cell(:x)),
result [](cell(:x)) <<(cell(:n)),
result [](cell(:x)) = list(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(result key?(cell(:x)),
result [](cell(:x)) <<(cell(:n)),
result [](cell(:x)) = list(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(result key?(cell(:x)),
result [](cell(:x)) <<(cell(:n)),
result [](cell(:x)) = list(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return an empty dict for an empty enumerable
[ show source ]
[] groupBy should ==({}) (1 ...(1)) groupBy should ==({}) set groupBy should ==({}) - - should return a dict with all distinct values as keys
[ show source ]
[](:abc, :cde :foo, :cde) groupBy keys should ==(set(:abc, :cde, :foo))
- - should group all the same values into a list
[ show source ]
[](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) groupBy should ==({}(1 =>([](1)), 2 =>([](2, 2)), 3 =>([](3, 3, 3)), 5 =>([](5, 5, 5, 5, 5)))) {}(foo: 42, bar: 55) groupBy should ==({}((:foo =>(42)) =>([](:foo =>(42))), (:bar =>(55)) =>([](:bar =>(55))))) - - should take one argument that is a message chain. the result of this will be the grouping factor and used as key
[ show source ]
[](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) groupBy(-(1)) should ==({}(0 =>([](1)), 1 =>([](2, 2)), 2 =>([](3, 3, 3)), 4 =>([](5, 5, 5, 5, 5)))) [](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) groupBy(asText) should ==({}("1" =>([](1)), "2" =>([](2, 2)), "3" =>([](3, 3, 3)), "5" =>([](5, 5, 5, 5, 5)))) - - should take two arguments that is an argument name and code. the result of this will be the grouping factor and used as key
[ show source ]
[](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) groupBy(x, x -(1)) should ==({}(0 =>([](1)), 1 =>([](2, 2)), 2 =>([](3, 3, 3)), 4 =>([](5, 5, 5, 5, 5)))) [](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) groupBy(x, x asText) should ==({}("1" =>([](1)), "2" =>([](2, 2)), "3" =>([](3, 3, 3)), "5" =>([](5, 5, 5, 5, 5)))) [](1, 2, 3, 2, 3, 3, 5, 5, 5, 5, 5) groupBy(x, x %(2) ==(0)) should ==({}(true =>([](2, 2)), false =>([](1, 3, 3, 3, 5, 5, 5, 5, 5))))
takes one argument and returns true if this element is in the collection. comparisons is done with ==.
[ show source ]
method(toFind,
self each(n,
if(toFind ==(cell(:n)),
return(true)))
return(false))
- - should return true if the element is in the enumeration
[ show source ]
[](1, 2, 3) include?(2) should be true CustomEnumerable include?("1second") should be true - - should return false if the element is not in the enumeration
[ show source ]
[](1, 2, 3) include?(0) should be false CustomEnumerable include?("2second") should be false
takes one, two, three or four arguments. all versions need an initial sum, code to execute, a place to put the current sum in the code, and a place to stick the current element of the enumerable. if one argument, it has to be a message chain. this message chain will be applied on the current sum. the element will be appended to the argument list of the last message send in the chain. the initial sum is the first element, and the code will be executed once less than the size of the enumerable due to this. if two arguments given, the first argument is the name of the variable to put the current element in, and the message will still be sent to the sum - and the initial sum works the same way as for one argument. when three arguments are given, the whole thing will be turned into a lexical closure, where the first argument is the name of the sum variable, the second argument is the name of the element variable, and the last argument is the code. when given four arguments, the only difference is that the first argument will be evaluated as the initial sum.
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
theCode = theCode deepCopy
elementName = genSym
theCode last <<(message(elementName))
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
call ground cell(elementName) = cell(:n)
sum = theCode evaluateOn(call ground, cell(:sum))))
return(cell(:sum)),
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
elementName = argName name
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
call ground cell(elementName) = cell(:n)
sum = theCode evaluateOn(call ground, cell(:sum))))
return(cell(:sum)),
if(
argCount ==(
3),
sumArgName = call arguments [](
0)
argName = call arguments [](
1)
theCode = call arguments [](
2)
lexicalCode = LexicalBlock createFrom(list(sumArgName, argName, theCode), call ground)
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
sum = lexicalCode call(cell(:sum), cell(:n))))
return(cell(:sum)),
if(
argCount ==(
4),
sum = call argAt(
0)
sumArgName = call arguments [](
1)
argName = call arguments [](
2)
theCode = call arguments [](
3)
lexicalCode = LexicalBlock createFrom(list(sumArgName, argName, theCode), call ground)
self each(n,
sum = lexicalCode call(cell(:sum), cell(:n)))
return(cell(:sum)),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))))
)
- - should take one argument that is a message chain and apply that on the sum, with the current arg as argument
[ show source ]
[](1, 2, 3) inject(+) should ==(6) [](1, 2, 3) inject(*(5) -) should ==(12) CustomEnumerable2 inject(-) should ==(9)
- - should take two arguments that is an argument name and a message chain and apply that on the sum
[ show source ]
[](1, 2, 3) inject(x, +(x *(2))) should ==(11) [](1, 2, 3) inject(x, *(5) -(x)) should ==(12) CustomEnumerable2 inject(x, -(x)) should ==(9)
- - should take three arguments that is the sum name, the argument name and code to apply
[ show source ]
[](1, 2, 3) inject(sum, x, sum +(x *(2))) should ==(11) [](1, 2, 3) inject(sum, x, sum *(5) -(x)) should ==(12) CustomEnumerable2 inject(sum, x, sum -(x)) should ==(9)
- - should take four arguments that is the initial value, the sum name, the argument name and code to apply
[ show source ]
[](1, 2, 3) inject(13, sum, x, sum +(x *(2))) should ==(25) [](1, 2, 3) inject(1, sum, x, sum *(5) -(x)) should ==(87) CustomEnumerable2 inject(100, sum, x, sum -(x)) should ==(25)
returns a string created by converting each element of the array to text, separated by an optional separator
[ show source ]
method(separator "",
result = ""
self each(index, n,
+=(result, (n asText))
if(index <(count -(1)), +=(result, separator)))
result)
- - should convert an empty list to an empty string
[ show source ]
[] join should ==("") set join should ==("") - - should convert a list with one element to it's equivalent as text
[ show source ]
[]("tempestuous turmoil") join should ==("tempestuous turmoil") [](1) join should ==("1") set(1) join should ==("1") - - should convert a list with multiple elements to a flat string of all its elements as text
[ show source ]
[]("a", "man", "walked", "into", "a", "bar...") join should ==("amanwalkedintoabar...") [](1, 2, 3, 4, 5) join should ==("12345")
- - should convert an empty list to an empty string
[ show source ]
[] join("glue") should ==("") set join("glue") should ==("") - - should convert a list with one element to it's equivalent as text
[ show source ]
[]("tempestuous turmoil") join("glue") should ==("tempestuous turmoil") set("tempestuous turmoil") join("glue") should ==("tempestuous turmoil") [](1) join("glue") should ==("1") set(1) join("glue") should ==("1") - - should convert a list with multiple elements to a flat string of all its elements as text
[ show source ]
[]("a", "man", "walked", "into", "a", "bar...") join(" ") should ==("a man walked into a bar...") [](1, 2, 3, 4, 5) join(", ") should ==("1, 2, 3, 4, 5") set(1, 2, 3) join(" ") split(" ") sort should ==([]("1", "2", "3"))
takes one or two arguments. if one argument is given, it will be evaluated as a message chain on each element in the enumerable, and then the result will be collected in a new List. if two arguments are given, the first one should be an unevaluated argument name, which will be bound inside the scope of executing the second piece of code. it's important to notice that the one argument form will establish no context, while the two argument form establishes a new lexical closure.
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
result <<(cell(:x)))
result,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
result <<(cell(:x)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))
)
- - should return an empty list for an empty enumerable
[ show source ]
[] map(x, x +(2)) should ==([]) {} map(x, x +(2)) should ==([]) set 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))
takes one or two arguments. if one argument is given, it will be evaluated as a message chain on each element in the enumerable, and then the result will be collected in a new Dict. if the message chain returns a pair, that pair will be used as key and value. if it's something else, that value will be the key, and the value for it will be nil. if two arguments are given, the first one should be an unevaluated argument name, which will be bound inside the scope of executing the second piece of code. it's important to notice that the one argument form will establish no context, while the two argument form establishes a new lexical closure.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x) kind ==("Pair"),
result [](x key) = x value,
result [](cell(:x)) = nil))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x) kind ==("Pair"),
result [](x key) = x value,
result [](cell(:x)) = nil))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return an empty dict for an empty enumerable
[ show source ]
[] map:dict(x, x +(2)) should ==(dict) {} map:dict(x, x +(2)) should ==(dict) set map:dict(x, x +(2)) should ==(dict) - - should return the same dict for something that only returns itself
[ show source ]
[](1, 2, 3) map:dict(x, x =>(x)) should ==(dict(1 =>(1), 2 =>(2), 3 =>(3)))
- - should take one argument and apply the inside
[ show source ]
[](1, 2, 3) map:dict(=>(2)) should ==(dict(1 =>(2), 2 =>(2), 3 =>(2))) [](1, 2, 3) map:dict(1 =>(1)) should ==(dict(1 =>(1)))
- - should take two arguments and apply the code with the argument name bound
[ show source ]
[](1, 2, 3) map:dict(x, x =>(x +(3))) should ==(dict(1 =>(4), 2 =>(5), 3 =>(6))) [](1, 2, 3) map:dict(x, x =>(1)) should ==(dict(1 =>(1), 2 =>(1), 3 =>(1))) [](1, 2, 3) map:dict(x, x) should ==(dict(1 =>(nil), 2 =>(nil), 3 =>(nil)))
nil
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
result <<(cell(:x)))
result,
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
result <<(cell(:x)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))
)
takes one or two arguments. if one argument is given, it will be evaluated as a message chain on each element in the enumerable, and then the result will be collected in a new Set. if two arguments are given, the first one should be an unevaluated argument name, which will be bound inside the scope of executing the second piece of code. it's important to notice that the one argument form will establish no context, while the two argument form establishes a new lexical closure.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
result <<(cell(:x)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
result <<(cell(:x)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return an empty set for an empty enumerable
[ show source ]
[] map:set(x, x +(2)) should ==(set) {} map:set(x, x +(2)) should ==(set) set map:set(x, x +(2)) should ==(set) - - should return the same set for something that only returns itself
[ show source ]
[](1, 2, 3) map:set(x, x) should ==(set(1, 2, 3))
- - should take one argument and apply the inside
[ show source ]
[](1, 2, 3) map:set(+(2)) should ==(set(3, 4, 5)) [](1, 2, 3) map:set(1) should ==(set(1))
- - should take two arguments and apply the code with the argument name bound
[ show source ]
[](1, 2, 3) map:set(x, x +(3)) should ==(set(4, 5, 6)) [](1, 2, 3) map:set(x, 1) should ==(set(1))
takes zero or more arguments that evaluates to lexical blocks. these blocks should all take one argument. these blocks will be chained together and applied on each element in the receiver. the final result will be collected into a list. the evaluation happens left-to-right, meaning the first method invoked will be the first argument.
[ show source ]
method(+blocks,
result = list
self each(n,
current = cell(:n)
blocks each(b, current = cell(:b) call(cell(:current)))
result <<(current))
result)
- - should take zero arguments and just return the elements in a list
[ show source ]
[](1, 2, 3) mapFn should ==([](1, 2, 3)) CustomEnumerable mapFn should ==([]("3first", "1second", "2third")) - - should take one lexical block argument and apply that to each element, and return the result in a list
[ show source ]
x = fn(arg, arg +(2)) [](1, 2, 3) mapFn(x) should ==([](3, 4, 5)) x = fn(arg, arg [](0 ..(2))) CustomEnumerable mapFn(x) should ==([]("3fi", "1se", "2th")) - - should take several lexical blocks and chain them together
[ show source ]
x = fn(arg, arg +(2)) x2 = fn(arg, arg *(2)) [](1, 2, 3) mapFn(x, x2) should ==([](6, 8, 10)) x = fn(arg, arg [](0 ..(2))) x2 = fn(arg, arg +("flurg")) CustomEnumerable mapFn(x, x2) should ==([]("3fiflurg", "1seflurg", "2thflurg"))
takes zero or more arguments that evaluates to lexical blocks. these blocks should all take one argument. these blocks will be chained together and applied on each element in the receiver. the final result will be collected into a dict. the evaluation happens left-to-right, meaning the first method invoked will be the first argument.
[ show source ]
method(+blocks,
result = dict
self each(n,
current = cell(:n)
blocks each(b, current = cell(:b) call(cell(:current)))
if(cell(:current) mimics?(Pair),
result [](current key) = current value,
result [](cell(:current)) = nil)
)
result)
- - should take zero arguments and just return the elements in a dict
[ show source ]
[](1, 2, 3) mapFn:dict should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) CustomEnumerable mapFn:dict should ==({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil))) - - should take one lexical block argument and apply that to each element, and return the result in a dict
[ show source ]
x = fn(arg, arg =>(arg +(2))) [](1, 2, 3) mapFn:dict(x) should ==({}(1 =>(3), 2 =>(4), 3 =>(5))) x = fn(arg, arg [](0 ..(2)) =>(arg [](0 ..(0)))) CustomEnumerable mapFn:dict(x) should ==({}("3fi" =>("3"), "1se" =>("1"), "2th" =>("2"))) - - should take several lexical blocks and chain them together
[ show source ]
x = fn(arg, arg =>(arg +(2))) x2 = fn(arg, arg value =>(arg key)) [](1, 2, 3) mapFn:dict(x, x2) should ==({}(3 =>(1), 4 =>(2), 5 =>(3))) x = fn(arg, arg [](0 ..(2))) x2 = fn(arg, arg =>("flurg")) CustomEnumerable mapFn:dict(x, x2) should ==({}("3fi" =>("flurg"), "1se" =>("flurg"), "2th" =>("flurg")))
takes zero or more arguments that evaluates to lexical blocks. these blocks should all take one argument. these blocks will be chained together and applied on each element in the receiver. the final result will be collected into a set. the evaluation happens left-to-right, meaning the first method invoked will be the first argument.
[ show source ]
method(+blocks,
result = set
self each(n,
current = cell(:n)
blocks each(b, current = cell(:b) call(cell(:current)))
result <<(current))
result)
- - should take zero arguments and just return the elements in a set
[ show source ]
[](1, 2, 3) mapFn:set should ==(set(1, 2, 3)) CustomEnumerable mapFn:set should ==(set("3first", "1second", "2third")) - - should take one lexical block argument and apply that to each element, and return the result in a set
[ show source ]
x = fn(arg, arg +(2)) [](1, 2, 3) mapFn:set(x) should ==(set(3, 4, 5)) x = fn(arg, arg [](0 ..(2))) CustomEnumerable mapFn:set(x) should ==(set("3fi", "1se", "2th")) - - should take several lexical blocks and chain them together
[ show source ]
x = fn(arg, arg +(2)) x2 = fn(arg, arg *(2)) [](1, 2, 3) mapFn:set(x, x2) should ==(set(6, 8, 10)) x = fn(arg, arg [](0 ..(2))) x2 = fn(arg, arg +("flurg")) CustomEnumerable mapFn:set(x, x2) should ==(set("3fiflurg", "1seflurg", "2thflurg"))
takes zero, one or two arguments. if zero arguments, returns the maximum elemnt ackording to the <=> ordering. if one argument, expects it to be a message chain. if that message chain, that will be used as a transform to create the element to compare with. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the transformer for comparison. the result will always be an element from the collection, or nil if the collection is empty.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
theMax = nil
theMaxVal = nil
self each(n,
x = cell(:n)
if(theMax nil?,
theMax = cell(:n)
theMaxVal = cell(:x),
if(theMaxVal <(cell(:x)),
theMax = cell(:n)
theMaxVal = cell(:x))))
theMax,
argCount ==(
1),
theCode = call arguments [](
0)
theMax = nil
theMaxVal = nil
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(theMax nil?,
theMax = cell(:n)
theMaxVal = cell(:x),
if(theMaxVal <(cell(:x)),
theMax = cell(:n)
theMaxVal = cell(:x))))
theMax,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
theMax = nil
theMaxVal = nil
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(theMax nil?,
theMax = cell(:n)
theMaxVal = cell(:x),
if(theMaxVal <(cell(:x)),
theMax = cell(:n)
theMaxVal = cell(:x))))
theMax,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return the maximum using the <=> operator if no arguments are given
[ show source ]
[](1, 2, 3, 4) max should ==(4) set(5, 6, 7, 153, 1) max should ==(153) []("a", "b", "c") max should ==("c") - - should accept a message chain, and use that to create the comparison criteria
[ show source ]
[](1, 2, 3, 4) max(*(-(1))) should ==(1) set(5, 6, 7, 153, 1) max(*(-(1))) should ==(1) []("abc", "bfooo", "cc") max(length) should ==("bfooo") - - should accept a variable name and code, and use that to create the comparison criteria
[ show source ]
[](1, 2, 3, 4) max(x, 10 -(x)) should ==(1) set(5, 6, 7, 153, 1) max(x, if(x >(100), -(x), x)) should ==(7) []("abc", "bfooo", "cc") max(x, x [](1)) should ==("bfooo")
nil
[ show source ]
method(toFind,
self each(n,
if(toFind ==(cell(:n)),
return(true)))
return(false))
- - should return true if the element is in the enumeration
[ show source ]
[](1, 2, 3) member?(2) should be true CustomEnumerable member?("1second") should be true - - should return false if the element is not in the enumeration
[ show source ]
[](1, 2, 3) member?(0) should be false CustomEnumerable member?("2second") should be false
takes zero, one or two arguments. if zero arguments, returns the minimum elemnt ackording to the <=> ordering. if one argument, expects it to be a message chain. if that message chain, that will be used as a transform to create the element to compare with. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the transformer for comparison. the result will always be an element from the collection, or nil if the collection is empty.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
theMin = nil
theMinVal = nil
self each(n,
x = cell(:n)
if(theMin nil?,
theMin = cell(:n)
theMinVal = cell(:x),
if(theMinVal >(cell(:x)),
theMin = cell(:n)
theMinVal = cell(:x))))
theMin,
argCount ==(
1),
theCode = call arguments [](
0)
theMin = nil
theMinVal = nil
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(theMin nil?,
theMin = cell(:n)
theMinVal = cell(:x),
if(theMinVal >(cell(:x)),
theMin = cell(:n)
theMinVal = cell(:x))))
theMin,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
theMin = nil
theMinVal = nil
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(theMin nil?,
theMin = cell(:n)
theMinVal = cell(:x),
if(theMinVal >(cell(:x)),
theMin = cell(:n)
theMinVal = cell(:x))))
theMin,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should return the minimum using the <=> operator if no arguments are given
[ show source ]
[](1, 2, 3, 4) min should ==(1) set(5, 6, 7, 153, 1) min should ==(1) []("a", "b", "c") min should ==("a") - - should accept a message chain, and use that to create the comparison criteria
[ show source ]
[](1, 2, 3, 4) min(*(-(1))) should ==(4) set(5, 6, 7, 153, 1) min(*(-(1))) should ==(153) []("abc", "bfooo", "cc") min(length) should ==("cc") - - should accept a variable name and code, and use that to create the comparison criteria
[ show source ]
[](1, 2, 3, 4) min(x, 10 -(x)) should ==(4) set(5, 6, 7, 153, 1) min(x, if(x >(100), -(x), x)) should ==(153) []("abc", "bfooo", "cc") min(x, x [](1)) should ==("abc")
takes zero, one or two arguments. if zero arguments, returns false if any of the elements yielded by each is true, otherwise true. if one argument, expects it to be a message chain. if that message chain, when applied to the current element returns a true value, the method returns false. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns true for any element, this method returns false, otherwise true.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
self each(n,
x = cell(:n)
if(cell(:x),
return(false)))
true,
argCount ==(
1),
theCode = call arguments [](
0)
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
return(false)))
true,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
return(false)))
true,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just check if any of the values are true, and then return false
[ show source ]
[](1, 2, 3) none? should be false [](nil, false, nil) none? should be true [](nil, false, true) none? should be false CustomEnumerable none? should be false
- - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) none?(==(2)) should be false [](nil, false, nil) none?(nil?) should be false [](nil, false, true) none?(==(2)) should be true CustomEnumerable none?(!=("foo")) should be false - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) none?(x, x ==(2)) should be false [](nil, false, nil) none?(x, x nil?) should be false [](nil, false, true) none?(x, x ==(2)) should be true CustomEnumerable none?(x, x !=("foo")) should be false
takes zero, one or two arguments. if zero arguments, returns true if exactly one of the elements is true, otherwise false. if one argument, expects it to be a message chain that will be used as a predicate. if that predicate returns true for exactly one element, returns true, otherwise false. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns true for exactly one element, returns true, otherwise false
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = false
self each(n,
x = cell(:n)
if(cell(:x),
if(result,
return(false),
result = true)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = false
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
if(result,
return(false),
result = true)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = false
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
if(result,
return(false),
result = true)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just check if exactly one of the values are true, and then return true
[ show source ]
[](1, 2, 3) one? should be false [](nil, false, nil) one? should be false [](nil, false, true) one? should be true CustomEnumerable one? should be false
- - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) one?(==(2)) should be true [](nil, false, nil) one?(nil?) should be false [](nil, false, true) one?(==(2)) should be false CustomEnumerable one?(==("3first")) should be true - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) one?(x, x ==(2)) should be true [](nil, false, nil) one?(x, x nil?) should be false [](nil, false, true) one?(x, x ==(2)) should be false CustomEnumerable one?(x, x ==("3first")) should be true
takes zero, one or two arguments. if zero arguments, will return a list containing two list, where the first list contains all true values, and the second all the false values. if one argument is given, it will be used as a predicate message chain, and the return lists will be based on the result of this predicate. finally, if three arguments are given, they will be turned into a lexical block and used as a predicate to determine the result value.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
resultTrue = list
resultFalse = list
self each(n,
x = cell(:n)
if(cell(:x), resultTrue, resultFalse) <<(cell(:n)))
list(resultTrue, resultFalse),
argCount ==(
1),
theCode = call arguments [](
0)
resultTrue = list
resultFalse = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x), resultTrue, resultFalse) <<(cell(:n)))
list(resultTrue, resultFalse),
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
resultTrue = list
resultFalse = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x), resultTrue, resultFalse) <<(cell(:n)))
list(resultTrue, resultFalse),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just divide all the true and false values
[ show source ]
[](1, 2, 3) partition should ==([]([](1, 2, 3), [])) [](nil, false, nil) partition should ==([]([], [](nil, false, nil))) [](nil, false, true) partition should ==([]([](true), [](nil, false))) CustomEnumerable partition should ==([]([]("3first", "1second", "2third"), [])) - - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) partition(==(2)) should ==([]([](2), [](1, 3))) [](nil, false, nil) partition(nil?) should ==([]([](nil, nil), [](false))) [](nil, false, true) partition(==(2)) should ==([]([], [](nil, false, true))) CustomEnumerable partition(!=("foo")) should ==([]([]("3first", "1second", "2third"), [])) - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) partition(x, x ==(2)) should ==([]([](2), [](1, 3))) [](nil, false, nil) partition(x, x nil?) should ==([]([](nil, nil), [](false))) [](nil, false, true) partition(x, x ==(2)) should ==([]([], [](nil, false, true))) CustomEnumerable partition(x, x !=("foo")) should ==([]([]("3first", "1second", "2third"), []))
takes zero, one or two arguments. if zero arguments, will return a list containing two dicts, where the first dict contains all true values, and the second all the false values. if one argument is given, it will be used as a predicate message chain, and the return dicts will be based on the result of this predicate. finally, if three arguments are given, they will be turned into a lexical block and used as a predicate to determine the result value.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
resultTrue = dict
resultFalse = dict
self each(n,
x = cell(:n)
place = if(cell(:x), resultTrue, resultFalse)
if(cell(:n) mimics?(Pair),
place [](n key) = n value,
place [](cell(:n)) = nil))
list(resultTrue, resultFalse),
argCount ==(
1),
theCode = call arguments [](
0)
resultTrue = dict
resultFalse = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
place = if(cell(:x), resultTrue, resultFalse)
if(cell(:n) mimics?(Pair),
place [](n key) = n value,
place [](cell(:n)) = nil))
list(resultTrue, resultFalse),
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
resultTrue = dict
resultFalse = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
place = if(cell(:x), resultTrue, resultFalse)
if(cell(:n) mimics?(Pair),
place [](n key) = n value,
place [](cell(:n)) = nil))
list(resultTrue, resultFalse),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just divide all the true and false values
[ show source ]
[](1, 2, 3) partition:dict should ==([]({}(1 =>(nil), 2 =>(nil), 3 =>(nil)), {})) [](nil, false, nil) partition:dict should ==([]({}, {}(nil =>(nil), false =>(nil)))) [](nil, false, true) partition:dict should ==([]({}(true =>(nil)), {}(nil =>(nil), false =>(nil)))) {}(foo: 42, bar: 55) partition:dict should ==([]({}(foo: 42, bar: 55), {})) CustomEnumerable partition:dict should ==([]({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil)), {})) - - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) partition:dict(==(2)) should ==([]({}(2 =>(nil)), {}(1 =>(nil), 3 =>(nil)))) [](nil, false, nil) partition:dict(nil?) should ==([]({}(nil =>(nil)), {}(false =>(nil)))) [](nil, false, true) partition:dict(==(2)) should ==([]({}, {}(nil =>(nil), false =>(nil), true =>(nil)))) {}(foo: 42, bar: 55) partition:dict(value ==(55)) should ==([]({}(bar: 55), {}(foo: 42))) CustomEnumerable partition:dict(!=("foo")) should ==([]({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil)), {})) - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) partition:dict(x, x ==(2)) should ==([]({}(2 =>(nil)), {}(1 =>(nil), 3 =>(nil)))) [](nil, false, nil) partition:dict(x, x nil?) should ==([]({}(nil =>(nil)), {}(false =>(nil)))) [](nil, false, true) partition:dict(x, x ==(2)) should ==([]({}, {}(nil =>(nil), false =>(nil), true =>(nil)))) {}(foo: 42, bar: 55) partition:dict(x, x value ==(55)) should ==([]({}(bar: 55), {}(foo: 42))) CustomEnumerable partition:dict(x, x !=("foo")) should ==([]({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil)), {}))
takes zero, one or two arguments. if zero arguments, will return a list containing two sets, where the first set contains all true values, and the second all the false values. if one argument is given, it will be used as a predicate message chain, and the return sets will be based on the result of this predicate. finally, if three arguments are given, they will be turned into a lexical block and used as a predicate to determine the result value.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
resultTrue = set
resultFalse = set
self each(n,
x = cell(:n)
if(cell(:x), resultTrue, resultFalse) <<(cell(:n)))
list(resultTrue, resultFalse),
argCount ==(
1),
theCode = call arguments [](
0)
resultTrue = set
resultFalse = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x), resultTrue, resultFalse) <<(cell(:n)))
list(resultTrue, resultFalse),
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
resultTrue = set
resultFalse = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x), resultTrue, resultFalse) <<(cell(:n)))
list(resultTrue, resultFalse),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just divide all the true and false values
[ show source ]
[](1, 2, 3) partition:set should ==([](set(1, 2, 3), set)) [](nil, false, nil) partition:set should ==([](set, set(nil, false))) [](nil, false, true) partition:set should ==([](set(true), set(nil, false))) CustomEnumerable partition:set should ==([](set("3first", "1second", "2third"), set)) - - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) partition:set(==(2)) should ==([](set(2), set(1, 3))) [](nil, false, nil) partition:set(nil?) should ==([](set(nil), set(false))) [](nil, false, true) partition:set(==(2)) should ==([](set, set(nil, false, true))) CustomEnumerable partition:set(!=("foo")) should ==([](set("3first", "1second", "2third"), set)) - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) partition:set(x, x ==(2)) should ==([](set(2), set(1, 3))) [](nil, false, nil) partition:set(x, x nil?) should ==([](set(nil), set(false))) [](nil, false, true) partition:set(x, x ==(2)) should ==([](set, set(nil, false, true))) CustomEnumerable partition:set(x, x !=("foo")) should ==([](set("3first", "1second", "2third"), set))
nil
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
theCode = theCode deepCopy
elementName = genSym
theCode last <<(message(elementName))
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
call ground cell(elementName) = cell(:n)
sum = theCode evaluateOn(call ground, cell(:sum))))
return(cell(:sum)),
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
elementName = argName name
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
call ground cell(elementName) = cell(:n)
sum = theCode evaluateOn(call ground, cell(:sum))))
return(cell(:sum)),
if(
argCount ==(
3),
sumArgName = call arguments [](
0)
argName = call arguments [](
1)
theCode = call arguments [](
2)
lexicalCode = LexicalBlock createFrom(list(sumArgName, argName, theCode), call ground)
sum = nil
self each(i, n,
if(i ==(0),
sum = cell(:n),
sum = lexicalCode call(cell(:sum), cell(:n))))
return(cell(:sum)),
if(
argCount ==(
4),
sum = call argAt(
0)
sumArgName = call arguments [](
1)
argName = call arguments [](
2)
theCode = call arguments [](
3)
lexicalCode = LexicalBlock createFrom(list(sumArgName, argName, theCode), call ground)
self each(n,
sum = lexicalCode call(cell(:sum), cell(:n)))
return(cell(:sum)),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))))
)
- - should take one argument that is a message chain and apply that on the sum, with the current arg as argument
[ show source ]
[](1, 2, 3) reduce(+) should ==(6) [](1, 2, 3) reduce(*(5) -) should ==(12) CustomEnumerable2 reduce(-) should ==(9)
- - should take two arguments that is an argument name and a message chain and apply that on the sum
[ show source ]
[](1, 2, 3) reduce(x, +(x *(2))) should ==(11) [](1, 2, 3) reduce(x, *(5) -(x)) should ==(12) CustomEnumerable2 reduce(x, -(x)) should ==(9)
- - should take three arguments that is the sum name, the argument name and code to apply
[ show source ]
[](1, 2, 3) reduce(sum, x, sum +(x *(2))) should ==(11) [](1, 2, 3) reduce(sum, x, sum *(5) -(x)) should ==(12) CustomEnumerable2 reduce(sum, x, sum -(x)) should ==(9)
- - should take four arguments that is the initial value, the sum name, the argument name and code to apply
[ show source ]
[](1, 2, 3) reduce(13, sum, x, sum +(x *(2))) should ==(25) [](1, 2, 3) reduce(1, sum, x, sum *(5) -(x)) should ==(87) CustomEnumerable2 reduce(100, sum, x, sum -(x)) should ==(25)
takes one or two arguments. if one argument is given, it will be applied as a message chain as a predicate. those elements that doesn't the predicate will be returned. if two arguments are given, they will be turned into a lexical block and used as a predicate to choose the elements that doesn't match.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = list
self each(n,
x = cell(:n)
unless(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
unless(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
unless(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take one argument that ends up being a predicate and return a list of the values that is false
[ show source ]
[](1, 2, 3) reject(>(1)) should ==([](1)) [](nil, false, nil) reject(nil?) should ==([](false)) [](nil, false, true) reject(==(2)) should ==([](nil, false, true)) CustomEnumerable reject([](0 ...(1)) ==("1")) should ==([]("3first", "2third")) - - should take two arguments that ends up being a predicate and return a list of the values that is false
[ show source ]
[](1, 2, 3) reject(x, x >(1)) should ==([](1)) [](nil, false, nil) reject(x, x nil?) should ==([](false)) [](nil, false, true) reject(x, x ==(2)) should ==([](nil, false, true)) CustomEnumerable reject(x, x ==("2third")) should ==([]("3first", "1second"))
takes one or two arguments. if one argument is given, it will be applied as a message chain as a predicate. those elements that doesn't the predicate will be returned. if two arguments are given, they will be turned into a lexical block and used as a predicate to choose the elements that doesn't match.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
self each(n,
x = cell(:n)
unless(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
unless(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
unless(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take one argument that ends up being a predicate and return a dict of the values that is false
[ show source ]
[](1, 2, 3) reject:dict(>(1)) should ==({}(1 =>(nil))) [](nil, false, nil) reject:dict(nil?) should ==({}(false =>(nil))) [](nil, false, true) reject:dict(==(2)) should ==({}(nil =>(nil), false =>(nil), true =>(nil))) {}(:foo =>(42), 2 =>(55)) reject:dict(key ==(2)) should ==({}(:foo =>(42))) CustomEnumerable reject:dict([](0 ...(1)) ==("1")) should ==({}("3first" =>(nil), "2third" =>(nil))) - - should take two arguments that ends up being a predicate and return a dict of the values that is false
[ show source ]
[](1, 2, 3) reject:dict(x, x >(1)) should ==({}(1 =>(nil))) [](nil, false, nil) reject:dict(x, x nil?) should ==({}(false =>(nil))) [](nil, false, true) reject:dict(x, x ==(2)) should ==({}(nil =>(nil), false =>(nil), true =>(nil))) {}(:foo =>(42), 2 =>(55)) reject:dict(x, x key ==(2)) should ==({}(:foo =>(42))) CustomEnumerable reject:dict(x, x ==("2third")) should ==({}("3first" =>(nil), "1second" =>(nil)))
takes one or two arguments. if one argument is given, it will be applied as a message chain as a predicate. those elements that doesn't the predicate will be returned. if two arguments are given, they will be turned into a lexical block and used as a predicate to choose the elements that doesn't match.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = set
self each(n,
x = cell(:n)
unless(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
unless(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
unless(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take one argument that ends up being a predicate and return a list of the values that is false
[ show source ]
[](1, 2, 3) reject:set(>(1)) should ==(set(1)) [](nil, false, nil) reject:set(nil?) should ==(set(false)) [](nil, false, true) reject:set(==(2)) should ==(set(nil, false, true)) CustomEnumerable reject:set([](0 ...(1)) ==("1")) should ==(set("3first", "2third")) - - should take two arguments that ends up being a predicate and return a list of the values that is false
[ show source ]
[](1, 2, 3) reject:set(x, x >(1)) should ==(set(1)) [](nil, false, nil) reject:set(x, x nil?) should ==(set(false)) [](nil, false, true) reject:set(x, x ==(2)) should ==(set(nil, false, true)) CustomEnumerable reject:set(x, x ==("2third")) should ==(set("3first", "1second"))
takes zero, one or two arguments. if zero arguments, will return a list with all the values that are true in the original collection. if one argument is given, it will be applied as a message chain, that should be a predicate. those elements that match the predicate will be returned. if two arguments are given, they will be turned into a lexical block and used as a predicate to choose elements.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = list
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a list with only the true values
[ show source ]
[](1, 2, 3) select should ==([](1, 2, 3)) [](nil, false, nil) select should ==([]) [](nil, false, true) select should ==([](true)) CustomEnumerable select should ==(CustomEnumerable asList)
- - should take one argument that ends up being a predicate and return a list of the values that is true
[ show source ]
[](1, 2, 3) select(>(1)) should ==([](2, 3)) [](nil, false, nil) select(nil?) should ==([](nil, nil)) [](nil, false, true) select(==(2)) should ==([]) CustomEnumerable select([](0 ...(1)) !=("1")) should ==([]("3first", "2third")) - - should take two arguments that ends up being a predicate and return a list of the values that is true
[ show source ]
[](1, 2, 3) select(x, x >(1)) should ==([](2, 3)) [](nil, false, nil) select(x, x nil?) should ==([](nil, nil)) [](nil, false, true) select(x, x ==(2)) should ==([]) CustomEnumerable select(x, x !=("2third")) should ==([]("3first", "1second"))
takes zero, one or two arguments. if zero arguments, will return a dict with all the values that are true in the original collection. if one argument is given, it will be applied as a message chain, that should be a predicate. those elements that match the predicate will be returned. if two arguments are given, they will be turned into a lexical block and used as a predicate to choose elements.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
self each(n,
x = cell(:n)
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a dict with only the true values
[ show source ]
[](1, 2, 3) select:dict should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) [](nil, false, nil) select:dict should ==({}) [](nil, false, true) select:dict should ==({}(true =>(nil))) {}(nil =>(42), true =>(55), blah: 222) select:dict should ==({}(nil =>(42), true =>(55), blah: 222)) CustomEnumerable select:dict should ==({}("3first" =>(nil), "2third" =>(nil), "1second" =>(nil))) - - should take one argument that ends up being a predicate and return a dict of the values that is true
[ show source ]
[](1, 2, 3) select:dict(>(1)) should ==({}(2 =>(nil), 3 =>(nil))) [](nil, false, nil) select:dict(nil?) should ==({}(nil =>(nil))) [](nil, false, true) select:dict(==(2)) should ==({}) {}(foo: 42, bar: 2324, quux: 42) select:dict(value ==(42)) should ==({}(foo: 42, quux: 42)) CustomEnumerable select:dict([](0 ...(1)) !=("1")) should ==({}("3first" =>(nil), "2third" =>(nil))) - - should take two arguments that ends up being a predicate and return a dict of the values that is true
[ show source ]
[](1, 2, 3) select:dict(x, x >(1)) should ==({}(2 =>(nil), 3 =>(nil))) [](nil, false, nil) select:dict(x, x nil?) should ==({}(nil =>(nil))) [](nil, false, true) select:dict(x, x ==(2)) should ==({}) {}(foo: 42, bar: 2324, quux: 42) select:dict(x, x value ==(42)) should ==({}(foo: 42, quux: 42)) CustomEnumerable select:dict(x, x !=("2third")) should ==({}("3first" =>(nil), "1second" =>(nil)))
takes zero, one or two arguments. if zero arguments, will return a set with all the values that are true in the original collection. if one argument is given, it will be applied as a message chain, that should be a predicate. those elements that match the predicate will be returned. if two arguments are given, they will be turned into a lexical block and used as a predicate to choose elements.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = set
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n))))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return a set with only the true values
[ show source ]
[](1, 2, 3) select:set should ==(set(1, 2, 3)) [](nil, false, nil) select:set should ==(set) [](nil, false, true) select:set should ==(set(true)) CustomEnumerable select:set should ==(set(*(CustomEnumerable asList)))
- - should take one argument that ends up being a predicate and return a set of the values that is true
[ show source ]
[](1, 2, 3) select:set(>(1)) should ==(set(2, 3)) [](nil, false, nil) select:set(nil?) should ==(set(nil)) [](nil, false, true) select:set(==(2)) should ==(set) CustomEnumerable select:set([](0 ...(1)) !=("1")) should ==(set("3first", "2third")) - - should take two arguments that ends up being a predicate and return a set of the values that is true
[ show source ]
[](1, 2, 3) select:set(x, x >(1)) should ==(set(2, 3)) [](nil, false, nil) select:set(x, x nil?) should ==(set(nil)) [](nil, false, true) select:set(x, x ==(2)) should ==(set) CustomEnumerable select:set(x, x !=("2third")) should ==(set("3first", "1second"))
takes zero, one or two arguments. if zero arguments, returns the first element that is true, otherwise false. if one argument, expects it to be a message chain. if that message chain, when applied to the current element returns a true value, that value is return. finally, if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and tested against the values in this element. if it returns true for any element, that value will be returned, otherwise false.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
self each(n,
x = cell(:n)
if(cell(:x),
return(it)))
false,
argCount ==(
1),
theCode = call arguments [](
0)
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
return(it)))
false,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
return(it)))
false,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and just check if any of the values are true, and then return it
[ show source ]
[](1, 2, 3) some should ==(1) [](nil, false, nil) some should be false [](nil, false, true) some should be true CustomEnumerable some should ==("3first") - - should take one argument that is a predicate that is applied to each element in the enumeration
[ show source ]
[](1, 2, 3) some(==(2) &&(3)) should ==(3) [](nil, false, nil) some(nil? &&(42)) should ==(42) [](nil, false, true) some(==(2) &&(3)) should be false CustomEnumerable some(!=("foo") &&("blarg")) should ==("blarg") - - should take two arguments that will be turned into a lexical block and applied
[ show source ]
[](1, 2, 3) some(x, x ==(2) &&(3)) should ==(3) [](nil, false, nil) some(x, x nil? &&(42)) should ==(42) [](nil, false, true) some(x, x ==(2) &&(3)) should be false CustomEnumerable some(x, x !=("foo") &&("blarg")) should ==("blarg")
will return a sorted list of all the entries of this enumerable object
[ show source ]
method( self asList sort)
- - should return a sorted list based on all the entries
[ show source ]
set(4, 4, 2, 1, 4, 23, 6, 4, 7, 21) sort should ==([](1, 2, 4, 6, 7, 21, 23))
takes one or two arguments that are used to transform the objects into something that can be sorted, then sorts based on that. if one argument, that argument is handled as a message chain, and if two arguments it will be turned into a lexical block and used.
[ show source ]
macro(
argCount = call arguments length
if(
argCount ==(
1),
theCode = call arguments [](
0)
map(x, list(theCode evaluateOn(call ground, cell(:x)), cell(:x))) sort map(second),
if(
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
map(x, list(lexicalCode call(cell(:x)), cell(:x))) sort map(second),
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext)))
)
- - should take one argument and apply that for sorting
[ show source ]
{}(a: 3, b: 2, c: 1) sortBy(value) should ==([](:c =>(1), :b =>(2), :a =>(3))) - - should take two arguments and turn that into a lexical block and use that for sorting
[ show source ]
{}(a: 3, b: 2, c: 1) sortBy(x, x value) should ==([](:c =>(1), :b =>(2), :a =>(3)))
returns an object created by summing all objects in the enumerable using the + operator. the default value for an empty enumerable will be nil.
[ show source ]
method( inject(+))
- - should return nil for an empty enumerable
[ show source ]
[] sum should be nil (1 ...(1)) sum should be nil set sum should be nil
- - should return the object in question for a one-object enumerable
[ show source ]
[](42) sum should ==(42) (1 ..(1)) sum should ==(1) set(5) sum should ==(5) []("str") sum should ==("str") - - should use the + operator to sum things
[ show source ]
[](32, 5, 111, 464) sum should ==((32 +(5) +(111) +(464))) []("foo", "bar", "bax") sum should ==("foobarbax")
takes one argument and returns a list with as many elements from the collection, or all elements if the requested number is larger than the size.
[ show source ]
method(howMany, self first(howMany))
- - should return a list with as many elements as requested
[ show source ]
[](1, 2, 3) take(0) should ==([]) [](1, 2, 3) take(1) should ==([](1)) [](1, 2, 3) take(2) should ==([](1, 2)) [](1, 2, 3) take(3) should ==([](1, 2, 3)) CustomEnumerable take(2) should ==([]("3first", "1second")) - - should not take more elements than the length of the collection
[ show source ]
[](1, 2, 3) take(4) should ==([](1, 2, 3)) [](1, 2, 3) take(10) should ==([](1, 2, 3)) CustomEnumerable take(200) should ==([]("3first", "1second", "2third"))
takes one argument and returns a dict with as many elements from the collection, or all elements if the requested number is larger than the size.
[ show source ]
method(howMany, self first:dict(howMany))
- - should return a dict with as many elements as requested
[ show source ]
[](1, 2, 3) take:dict(0) should ==({}) [](1, 2, 3) take:dict(1) should ==({}(1 =>(nil))) [](1, 2, 3) take:dict(2) should ==({}(1 =>(nil), 2 =>(nil))) [](1, 2, 3) take:dict(3) should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) {}(foo: 42, bar: 66) take:dict(0) should ==({}) {}(foo: 42, bar: 66) take:dict(2) should ==({}(foo: 42, bar: 66)) CustomEnumerable take:dict(2) should ==({}("3first" =>(nil), "1second" =>(nil))) - - should not take more elements than the length of the collection
[ show source ]
[](1, 2, 3) take:dict(4) should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) [](1, 2, 3) take:dict(10) should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) CustomEnumerable take:dict(200) should ==({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil)))
takes one argument and returns a set with as many elements from the collection, or all elements if the requested number is larger than the size.
[ show source ]
method(howMany, self first:set(howMany))
- - should return a set with as many elements as requested
[ show source ]
[](1, 2, 3) take:set(0) should ==(set) [](1, 2, 3) take:set(1) should ==(set(1)) [](1, 2, 3) take:set(2) should ==(set(1, 2)) [](1, 2, 3) take:set(3) should ==(set(1, 2, 3)) CustomEnumerable take:set(2) should ==(set("3first", "1second")) - - should not take more elements than the length of the collection
[ show source ]
[](1, 2, 3) take:set(4) should ==(set(1, 2, 3)) [](1, 2, 3) take:set(10) should ==(set(1, 2, 3)) CustomEnumerable take:set(200) should ==(set("3first", "1second", "2third"))
takes zero, one or two arguments. it will evaluate a predicate once for each element, and collect all the elements until the predicate returns false for the first time. at that point the collected list will be returned. if zero arguments, the predicate is the element itself. if one argument, expects it to be a message chain to apply as a predicate. if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = list
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n)),
return(result)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = list
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n)),
return(result)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = list
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n)),
return(result)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return everything up until the point where a value is false
[ show source ]
[](1, 2, 3) takeWhile should ==([](1, 2, 3)) [](1, 2, nil, false) takeWhile should ==([](1, 2)) [](1, 2, false, 3, 4, nil, false) takeWhile should ==([](1, 2)) CustomEnumerable takeWhile should ==([]("3first", "1second", "2third")) - - should take one argument and apply it as a message chain, return a list with all elements until the block returns false
[ show source ]
[](1, 2, 3) takeWhile(<(3)) should ==([](1, 2)) [](1, 2, 3) takeWhile(!=(2)) should ==([](1)) CustomEnumerable takeWhile(!=("2third")) should ==([]("3first", "1second")) - - should take two arguments and apply the lexical block created from it, and return a list with all elements until the block returns false
[ show source ]
[](1, 2, 3) takeWhile(x, x <(3)) should ==([](1, 2)) [](1, 2, 3) takeWhile(x, x !=(2)) should ==([](1)) CustomEnumerable takeWhile(x, x !=("2third")) should ==([]("3first", "1second"))
takes zero, one or two arguments. it will evaluate a predicate once for each element, and collect all the elements until the predicate returns false for the first time. at that point the collected dict will be returned. if zero arguments, the predicate is the element itself. if one argument, expects it to be a message chain to apply as a predicate. if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = dict
self each(n,
x = cell(:n)
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil),
return(result)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = dict
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil),
return(result)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = dict
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
if(cell(:n) mimics?(Pair),
result [](n key) = n value,
result [](cell(:n)) = nil),
return(result)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return everything up until the point where a value is false
[ show source ]
[](1, 2, 3) takeWhile:dict should ==({}(1 =>(nil), 2 =>(nil), 3 =>(nil))) [](1, 2, nil, false) takeWhile:dict should ==({}(1 =>(nil), 2 =>(nil))) [](1, 2, false, 3, 4, nil, false) takeWhile:dict should ==({}(1 =>(nil), 2 =>(nil))) {}(foo: 42, bar: 55) takeWhile:dict should ==({}(foo: 42, bar: 55)) CustomEnumerable takeWhile:dict should ==({}("3first" =>(nil), "1second" =>(nil), "2third" =>(nil))) - - should take one argument and apply it as a message chain, return a list with all elements until the block returns false
[ show source ]
[](1, 2, 3) takeWhile:dict(<(3)) should ==({}(1 =>(nil), 2 =>(nil))) [](1, 2, 3) takeWhile:dict(!=(2)) should ==({}(1 =>(nil))) [](:foo =>(42), :bar =>(55), :quux =>(1242)) takeWhile:dict(value <(56)) should ==({}(foo: 42, bar: 55)) CustomEnumerable takeWhile:dict(!=("2third")) should ==({}("3first" =>(nil), "1second" =>(nil))) - - should take two arguments and apply the lexical block created from it, and return a list with all elements until the block returns false
[ show source ]
[](1, 2, 3) takeWhile:dict(x, x <(3)) should ==({}(1 =>(nil), 2 =>(nil))) [](1, 2, 3) takeWhile:dict(x, x !=(2)) should ==({}(1 =>(nil))) [](:foo =>(42), :bar =>(55), :quux =>(1242)) takeWhile:dict(x, x value <(56)) should ==({}(foo: 42, bar: 55)) CustomEnumerable takeWhile:dict(x, x !=("2third")) should ==({}("3first" =>(nil), "1second" =>(nil)))
takes zero, one or two arguments. it will evaluate a predicate once for each element, and collect all the elements until the predicate returns false for the first time. at that point the collected set will be returned. if zero arguments, the predicate is the element itself. if one argument, expects it to be a message chain to apply as a predicate. if two arguments are given, the first argument is an unevaluated name and the second is a code element. these will together be turned into a lexical block and used as the predicate.
[ show source ]
macro(
argCount = call arguments length
cond(
argCount ==(
0),
result = set
self each(n,
x = cell(:n)
if(cell(:x),
result <<(cell(:n)),
return(result)))
result,
argCount ==(
1),
theCode = call arguments [](
0)
result = set
self each(n,
x = theCode evaluateOn(call ground, cell(:n))
if(cell(:x),
result <<(cell(:n)),
return(result)))
result,
argCount ==(
2),
argName = call arguments [](
0)
theCode = call arguments [](
1)
result = set
lexicalCode = LexicalBlock createFrom(list(argName, theCode), call ground)
self each(n,
x = lexicalCode call(cell(:n))
if(cell(:x),
result <<(cell(:n)),
return(result)))
result,
error!(Condition Error Invocation NoMatch, message: call message, context: call currentContext))
)
- - should take zero arguments and return everything up until the point where a value is false
[ show source ]
[](1, 2, 3) takeWhile:set should ==(set(1, 2, 3)) [](1, 2, nil, false) takeWhile:set should ==(set(1, 2)) [](1, 2, false, 3, 4, nil, false) takeWhile:set should ==(set(1, 2)) CustomEnumerable takeWhile:set should ==(set("3first", "1second", "2third")) - - should take one argument and apply it as a message chain, return a list with all elements until the block returns false
[ show source ]
[](1, 2, 3) takeWhile:set(<(3)) should ==(set(1, 2)) [](1, 2, 3) takeWhile:set(!=(2)) should ==(set(1)) CustomEnumerable takeWhile:set(!=("2third")) should ==(set("3first", "1second")) - - should take two arguments and apply the lexical block created from it, and return a list with all elements until the block returns false
[ show source ]
[](1, 2, 3) takeWhile:set(x, x <(3)) should ==(set(1, 2)) [](1, 2, 3) takeWhile:set(x, x !=(2)) should ==(set(1)) CustomEnumerable takeWhile:set(x, x !=("2third")) should ==(set("3first", "1second"))
takes zero or more arguments, where all arguments should be a list, except that the last might also be a lexical block. zip will create a list of lists, where each internal list is a combination of the current element, and the corresponding elements from all the lists. if the lists are shorter than this collection, nils will be supplied. if a lexical block is provided, it will be called with each list created, and if that's the case nil will be returned from zip
[ show source ]
method(+listsAndFns,
theFn = listsAndFns last
if(cell(:theFn) &&(cell(:theFn) mimics?(LexicalBlock)),
listsAndFns = listsAndFns [](0 ..(0 -(2)))
listsAndFns map!(x,
if(x mimics?(Sequence),
x,
x seq))
self each(n,
internal = list(cell(:n))
listsAndFns each(n2,
val = if(n2 next?, n2 next, nil)
internal <<(cell(:val)))
cell(:theFn) call(internal))
nil,
listsAndFns map!(x,
if(x mimics?(Sequence),
x,
x seq))
result = list
self each(n,
internal = list(cell(:n))
listsAndFns each(n2,
val = if(n2 next?, n2 next, nil)
internal <<(cell(:val)))
result <<(internal))
result))
- - should take zero arguments and just zip the elements
[ show source ]
[](1, 2, 3) zip should ==([]([](1), [](2), [](3)))
- - should take one argument as a list and zip the elements together
[ show source ]
[](1, 2, 3) zip([](5, 6, 7)) should ==([]([](1, 5), [](2, 6), [](3, 7))) [](1, 2, 3) zip([](5, 6, 7, 8)) should ==([]([](1, 5), [](2, 6), [](3, 7)))
- - should take one argument as a seq and zip the elements together
[ show source ]
[](1, 2, 3) zip([](5, 6, 7) seq) should ==([]([](1, 5), [](2, 6), [](3, 7))) [](1, 2, 3) zip([](5, 6, 7, 8) seq) should ==([]([](1, 5), [](2, 6), [](3, 7)))
- - should supply nils if the second list isn't long enough
[ show source ]
[](1, 2, 3) zip([](5, 6)) should ==([]([](1, 5), [](2, 6), [](3, nil)))
- - should zip together several lists
[ show source ]
[](1, 2, 3) zip([](5, 6, 7), [](10, 11, 12), [](15, 16, 17)) should ==([]([](1, 5, 10, 15), [](2, 6, 11, 16), [](3, 7, 12, 17)))
- - should take a fn as last argument and call that instead of returning a list
[ show source ]
x = [] [](1, 2, 3) zip([](5, 6, 7), fn(arg, x <<(arg))) should be nil x should ==([]([](1, 5), [](2, 6), [](3, 7)))
takes zero or more arguments, where all arguments should be lists or sequences. zip:set will create a list of set, where each internal set is a combination of the current element, and the corresponding elements from all the lists. if the lists are shorter than this collection, nils will be supplied.
[ show source ]
method(+lists,
lists map!(x,
if(x mimics?(Sequence),
x,
x seq))
result = list
self each(n,
internal = set(cell(:n))
lists each(n2,
val = if(n2 next?, n2 next, nil)
internal <<(cell(:val)))
result <<(internal))
result)
- - should take zero arguments and just zip the elements
[ show source ]
[](1, 2, 3) zip:set should ==([](set(1), set(2), set(3)))
- - should take one argument as a list and zip the elements together
[ show source ]
[](1, 2, 3) zip:set([](5, 6, 7)) should ==([](set(1, 5), set(2, 6), set(3, 7))) [](1, 2, 3) zip:set([](5, 6, 7, 8)) should ==([](set(1, 5), set(2, 6), set(3, 7)))
- - should take one argument as a seq and zip the elements together
[ show source ]
[](1, 2, 3) zip:set([](5, 6, 7) seq) should ==([](set(1, 5), set(2, 6), set(3, 7))) [](1, 2, 3) zip:set([](5, 6, 7, 8) seq) should ==([](set(1, 5), set(2, 6), set(3, 7)))
- - should supply nils if the second list isn't long enough
[ show source ]
[](1, 2, 3) zip:set([](5, 6)) should ==([](set(1, 5), set(2, 6), set(3, nil)))
- - should zip together several lists
[ show source ]
[](1, 2, 3) zip:set([](5, 6, 7), [](10, 11, 12), [](15, 16, 17)) should ==([](set(1, 5, 10, 15), set(2, 6, 11, 16), set(3, 7, 12, 17)))