sequtils: findIt (#25134)

Complements `anyIt`, `find`, etc, plugging an odd gap in the `xxxIt`
family of functions
This commit is contained in:
Jacek Sieka
2025-09-09 20:05:12 +02:00
committed by GitHub
parent c8456eacd5
commit 5ba279276e
2 changed files with 52 additions and 21 deletions

View File

@@ -258,6 +258,17 @@ block: # any
doAssert any(anumbers, proc (x: int): bool = return x > 8) == true
doAssert any(anumbers, proc (x: int): bool = return x > 9) == false
block: # findIt
let
numbers = @[1, 4, 5, 8, 9, 7, 4]
anumbers = [1, 4, 5, 8, 9, 7, 4]
len0seq: seq[int] = @[]
doAssert findIt(numbers, it == 4) == 1
doAssert findIt(numbers, it > 9) == -1
doAssert findIt(len0seq, true) == -1
doAssert findIt(anumbers, it > 8) == 4
doAssert findIt(anumbers, it > 9) == -1
block: # anyIt
let
numbers = @[1, 4, 5, 8, 9, 7, 4]