diff --git a/changelogs/changelog_2_0_0.md b/changelogs/changelog_2_0_0.md index e8dbbc27c1..42c25946aa 100644 --- a/changelogs/changelog_2_0_0.md +++ b/changelogs/changelog_2_0_0.md @@ -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`. diff --git a/lib/core/macrocache.nim b/lib/core/macrocache.nim index ffd07abb1c..39999fa113 100644 --- a/lib/core/macrocache.nim +++ b/lib/core/macrocache.nim @@ -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: