18 lines
458 B
Text
18 lines
458 B
Text
|
|
s@(Sequence traits) forwardDifference
|
||
|
|
[
|
||
|
|
s allButFirst with: s allButLast collect: #- `er
|
||
|
|
].
|
||
|
|
|
||
|
|
s@(Sequence traits) forwardDifference
|
||
|
|
"Without creating two intermediate throwaway Sequences."
|
||
|
|
[
|
||
|
|
result ::= s allButFirst.
|
||
|
|
result doWithIndex: [| :nextValue :index | result at: index infect: [| :oldValue | oldValue - (s at: index)].
|
||
|
|
result
|
||
|
|
].
|
||
|
|
|
||
|
|
s@(Sequence traits) forwardDifference: n
|
||
|
|
[
|
||
|
|
(0 below: n) inject: s into: [| :seq :_ | seq forwardDifference]
|
||
|
|
].
|