mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-22 15:25:22 +00:00
sequtils: findIt (#25134)
Complements `anyIt`, `find`, etc, plugging an odd gap in the `xxxIt` family of functions
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user