Let's say I have the following sequences:
var s1: seq[int] = @[]
var s2: seq[int]
var s3: seq[int] = nil
var s4: seq[int] = newSeq[int](4)
Which of these are typically considered "empty"? And what is the most idiomatic way to test if they are empty?
Right now I am just checking if len
is 0
:
proc doSomething(s: seq[int]) =
if s.len() == 0:
echo("Your sequence is empty.")
else:
# do something
The strutils module provides an isNullOrEmpty
proc for strings: https://nim-lang.org/docs/strutils.html#isNilOrEmpty,string
As you can see in its implementation it just checks for len(s) == 0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With