mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +00:00
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:
@@ -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`.
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user