motoko-base icon indicating copy to clipboard operation
motoko-base copied to clipboard

change revRange to same argument types as range

Open borovan opened this issue 3 years ago • 2 comments

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); };

borovan avatar May 06 '22 11:05 borovan

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 CLA[^1].

If you decide to agree with it, please visit this issue and read the instructions there.

— The DFINITY Foundation [^1]: Contributor License Agreement

dfinity-droid-prod[bot] avatar May 06 '22 11:05 dfinity-droid-prod[bot]

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.

borovan avatar May 07 '22 07:05 borovan