As an enthusiastic Squeak User, IWLT be able to reference many cells at once using a formula, in order to aggregate data. The protocol should be very convenient again.
Acceptance criteria
[ ] Add the following protocol to the receiver of a cell formula:
[ ] #fromRow:column:toRow:column: - returns a collection object (CO) that contains all values from the cells within the specified range. In particular, the CO should understand selectors like #sum, #+, #max and so on.
[ ] #fromColumn:row:toColumn:row: - analogous with swapped parameters
[ ] #from:to: - the argument are points. Works analogously to #fromRow:column:toRow:column. (x goes column and y goes row)
[ ] COs returned by the selectors above are immutable
[ ] COs returned by the selectors above understand the following messages, in addition to normal Collection protocol:
[ ] #collect: - returns another CO, with a variable parameter size block:
[ ] When called with a block that takes one argument, works as usual in any collection.
[ ] When called with a block that takes three args, works analogously to Matrix>>#withIndicesCollect:. The argument must be a block that takes the following arguments in order: value, rowIndex, and columnIndex.
[ ] When called with a block that takes two args, the second arg must be a point whose coordinates are forwarded to a block with three args (where x is columnIndex and y is rowIndex)
[ ] Symbols work as well
[ ] #select: and #reject: - return another CO, with a variable parameter size block:
[ ] When called with a block that takes one argument, works as usual in any collection.
[ ] When called with a block that takes two or three arguments, returns a new CO that contains all elements of the receiver that match the block (don't match it in case of #reject:). The block has the same parameters as #collect: above.
[ ] Symbols work as well
[ ] #select:thenCollect: - works as a shorthand for (myCo select: aBlock) collect: anotherBlock, even if the blocks take many or not the same number of arguments
Example
I want to evaluate a formula like the following (this is NOT a practical but rather a feasibility example):
^(((self from: 1 @ 1 to: 2 @ 3)
select: #isEven
thenCollect: [:v :x :y | v + x - y])
select: [:v :p | p x isEven xor: (p y isEven)])
detect: #isPrime ifNone: 42
As an enthusiastic Squeak User, IWLT be able to reference many cells at once using a formula, in order to aggregate data. The protocol should be very convenient again.
Acceptance criteria
#fromRow:column:toRow:column:
- returns a collection object (CO) that contains all values from the cells within the specified range. In particular, the CO should understand selectors like#sum
,#+
,#max
and so on.#fromColumn:row:toColumn:row:
- analogous with swapped parameters#from:to:
- the argument are points. Works analogously to#fromRow:column:toRow:column
. (x goes column and y goes row)#collect:
- returns another CO, with a variable parameter size block:Matrix>>#withIndicesCollect:
. The argument must be a block that takes the following arguments in order: value, rowIndex, and columnIndex.#select:
and#reject:
- return another CO, with a variable parameter size block:#collect:
above.#select:thenCollect:
- works as a shorthand for(myCo select: aBlock) collect: anotherBlock
, even if the blocks take many or not the same number of argumentsExample
I want to evaluate a formula like the following (this is NOT a practical but rather a feasibility example):