BackwardsIndex overload for CacheSeq.[] (#22043)

* Add `BackwardsIndex` support for `CacheSeq`

* Add changelog entry

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Jake Leahy
2023-06-10 22:43:32 +10:00
committed by GitHub
parent b2d7761975
commit d3af0882cf
2 changed files with 14 additions and 0 deletions

View File

@@ -335,6 +335,7 @@
+ Added bindings to [`Array.shift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
and [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask).
+ Added `toDateString`, `toISOString`, `toJSON`, `toTimeString`, `toUTCString` converters for `DateTime`.
- Added `BackwardsIndex` overload for `CacheSeq`.
- Added support for nested `with` blocks in `std/with`.

View File

@@ -127,6 +127,19 @@ proc `[]`*(s: CacheSeq; i: int): NimNode {.magic: "NcsAt".} =
mySeq.add(newLit(42))
assert mySeq[0].intVal == 42
proc `[]`*(s: CacheSeq; i: BackwardsIndex): NimNode =
## Returns the `i`th last value from `s`.
runnableExamples:
import std/macros
const mySeq = CacheSeq"backTest"
static:
mySeq &= newLit(42)
mySeq &= newLit(7)
assert mySeq[^1].intVal == 7 # Last item
assert mySeq[^2].intVal == 42 # Second last item
s[s.len - int(i)]
iterator items*(s: CacheSeq): NimNode =
## Iterates over each item in `s`.
runnableExamples: