change revRange to same argument types as range#374
change revRange to same argument types as range#374borovan wants to merge 1 commit intocaffeinelabs:masterfrom
Conversation
This allows it to iterate returning ?Nat instead of ?Int so it can be used in arrays.
As range starts at Nat I figured that negative numbers weren't that important anyway. Maybe range should be (Nat, Nat) too? So then you've got the two functions that are easily used with arrays. Could always add rangeInt separately.
This is my first pull request so if I've screwed anything up DONT HOLD BACK!
Here are the tests I used
// revRange
do {
let rev = LIter.revRange(0, 0);
assert(rev.next() == ?0);
assert(rev.next() == null);
};
do {
let rev = LIter.revRange(3, 1);
assert(rev.next() == ?3);
assert(rev.next() == ?2);
assert(rev.next() == ?1);
assert(rev.next() == null);
};
|
Dear @borovan, In order to potentially merge your code in this open-source repository and therefore proceed with your contribution, we need to have your approval on DFINITY's CLA1. If you decide to agree with it, please visit this issue and read the instructions there. — The DFINITY Foundation Footnotes
|
nomeata
left a comment
There was a problem hiding this comment.
I think the original plan was to produce a Nat iterator, and the only reason to accept an Int in the bound is so that you can write something like a.len() - 1 without worrying about underflow. But that design isn't beyond challenging, I'd say.
|
https://forum.dfinity.org/t/reversing-an-array/12724/18?u=borovan Yeah maybe icme has a point. The methods in Iter are probably fine but you just have to use Int.abs() on the result within an array. Just wanted you see it from the developers perspective. |
d52aecd to
08507fc
Compare
This allows it to iterate returning ?Nat instead of ?Int so it can be used in arrays.
As range starts at Nat I figured that negative numbers weren't that important anyway. Maybe range should be (Nat, Nat) too? So then you've got the two functions that are easily used with arrays. Could always add rangeInt separately.
This is my first pull request so if I've screwed anything up DONT HOLD BACK!
Here are the tests I used
// revRange
do {
let rev = LIter.revRange(0, 0);
assert(rev.next() == ?0);
assert(rev.next() == null);
};
do {
let rev = LIter.revRange(3, 1);
assert(rev.next() == ?3);
assert(rev.next() == ?2);
assert(rev.next() == ?1);
assert(rev.next() == null);
};