Truthiness
In Shim, non-empty and non-zero values are considered truthy. Empty containers and zero values are falsy. Here are some examples of falsy values:
falseNone00.0""[]{:}{,}()
Essentially all other values are truthy. All structs are truthy, non-zero-sized tuples are truthy, non-empty lists/dicts/sets are truthy, non-empty strings are truthy, and functions are truthy.
let values = [
false,
None,
0,
0.0,
"",
[],
{:},
{,},
(),
true,
1.0,
-1,
"test",
["non-empty"],
{"non-empty",},
{"key": "non-empty"},
("val",),
]
for value in values {
let rstr = repr(value)
for _ in rstr.len()..21 {
rstr += " "
}
print(rstr, bool(value))
}Press the play button to execute