Bool type

Boolean type. The only objects are true and false

Constructors

Bool(x:Any)
Convert to Bool. Str, Arr and Hash of non-zero size return true. Bool returns as is. Null returns false. Int returns true if it is not zero.

Parameters

xBool or Int or Str or Arr or Hash or Null

Returns

Bool
Bool(mm:MultiMethod) Source: bootstrap.ngs:60
Whether MultiMethod has any methods
Bool(al:ArrLike) Source: stdlib.ngs:730
Check whether al has any elements.
Bool(hl:HashLike) Source: stdlib.ngs:819
Check whether hl has any elements.

Returns

Bool
Bool(fb:FullBox) Source: stdlib.ngs:2840
Always true
Bool(eb:EmptyBox) Source: stdlib.ngs:2843
Always false
Bool(s:Success) Source: stdlib.ngs:3102
Convert Success to Bool (true)

Returns

true
Bool(f:Failure) Source: stdlib.ngs:3106
Convert Failure to Bool (false)

Returns

false
Bool(d:ArrDiff) Source: stdlib.ngs:3238
Check whether there is a difference

Returns

Bool

Example

arr_diff = Diff(current, desired)
# Implicit Bool() when using in "if": if arr_diff -> if Bool(arr_diff)
if arr_diff {
  echo("Will make modifications to the resource")
  if arr_diff.add {
    ...
  }
  if arr_diff.remove {
    ...
  }
}
Bool(d:HashDiff) Source: stdlib.ngs:3274
Whether there is a difference

Returns

Bool

Example

hash_diff = Diff(current_properties, desired_properties)
# Implicit Bool() when using in "if": if hash_diff -> if Bool(hash_diff)
if hash_diff {
  echo("Will make modifications to the resource")
  if hash_diff.add {
    ...
  }
  if hash_diff.remove {
    ...
  }
  if hash_diff.change {
    ...
  }
}
Bool(p:Path) Source: stdlib.ngs:4150
Checks whether the path is accessible using access(2) and F_OK.

Returns

Bool
Bool(p:Path)experimental Source: stdlib.ngs:4163
Check whether file system object at given path is of the given type.

Example

if File("myfile.txt") ...
if Dir("my_tmp_dir") ...
Bool(pp:ProcessesPipeline) Source: stdlib.ngs:4824
Wait for all process to finish and see whether all exit codes are 0

Returns

Bool

Example

if $(test -f myfile) ... # if runs Bool() on any non-Bool condition expression
Bool(ms:MatchSuccess) Source: stdlib.ngs:5558
Convert successful match to Bool (true)

Returns

true
Bool(mf:MatchFailure) Source: stdlib.ngs:5562
Convert failed match to Bool (false)

Returns

false
Bool(t:Time) Source: stdlib.ngs:6263
Undocumented
Bool(rd:ResDef) Source: autoload/Res.ngs:107
Check whether any resources were found.

Returns

Bool

Example

# Implicit Bool(): if expr -> if Bool(expr)
if AWS::Instance({"env": "dev", "role": "edge"}) {
  echo("There is at least one edge server in dev environment")
}
Bool(i:MapIter) Source: autoload/Iter.ngs:119
EXPERIMENTAL! Do not use!
Bool(i:FilterIter) Source: autoload/Iter.ngs:173
EXPERIMENTAL! Do not use!
Bool(i:FunIter) Source: autoload/Iter.ngs:220
EXPERIMENTAL! Do not use!
Bool(i:ConstIter) Source: autoload/Iter.ngs:235
Convert ConstIter to Bool (true).

Returns

true
Bool(i:RangeIter) Source: autoload/Iter.ngs:265
Check whether there is at least one uniterated item in range.

Returns

Bool. true: next() will return next element. false: next() will throw NoNext
Bool(i:ArrIter) Source: autoload/Iter.ngs:306
Check whether there are more array elements to iterate over.

Returns

Bool. true: next() will return next element. false: next() will throw NoNext
Bool(i:HashIter) Source: autoload/Iter.ngs:347
Check whether there are more pairs to iterate over.

Returns

Bool. true: next() will return next pair. false: next() will throw NoNext
Bool(s:Set) Source: autoload/Set.ngs:39
Check whether the set is not empty
Bool(t:Table) Source: autoload/Table.ngs:106
Check whether there are any rows in the table.
Bool(d:Description)
Undocumented
Bool(t:Terminal) Source: autoload/Terminal.ngs:54
Undocumented

Methods

==(a:Bool, b:Bool)
Compare booleans
assert(condition:Bool, msg:Str) Source: stdlib.ngs:75
Throws AssertFail with givens message if condition is false

Returns

Unspecified, do not count on this value

Example

my_array=[]
# ... Code that adds elements to my_array ...
assert(my_array.len() > 3, "my_array must have more than 3 elements")  # AssertFail exception, with the given message
assert(condition:Bool) Source: stdlib.ngs:82
Throws AssertFail if condition is false

Returns

Unspecified, do not count on this value

Example

my_array=[]
# ... Code that adds elements to my_array ...
assert(my_array.len() > 3)  # AssertFail exception, with "Assertion failed" message
code(b:Bool) Source: stdlib.ngs:3280
Convert a Bool to NGS code that would produce the given Bool when executed. Not fully functional yet.

Returns

Str
Diff(a:Arr, b:Arr, full:Bool=false) Source: stdlib.ngs:3162
Compare arrays. Warning: by default Hash is used so internal Hash keys comparison is used, not ==

Parameters

fullDo not use Hash, work slower but use == comparison.

Example

Diff([1,2], [2,3])  # .add = [3] .remove = [1]
Diff(a:Arr, b:Arr, full:Bool=false) Source: stdlib.ngs:3198
Compare arrays. Warning: by default Hash is used so internal Hash keys comparison is used, not ==

Parameters

bArr[PartialPresence]
fullDo not use Hash, work slower but use == comparison.

Returns

ArrDiff

Example

Diff([1,2,3], [Present(1)])  # <ArrDiff add=[] remove=[]>
Diff([1,2,3], [Present(5)])  # <ArrDiff add=[5] remove=[]>
Diff([1,2,3], [Absent(1)])   # <ArrDiff add=[] remove=[1]>
Diff([1,2,3], [Absent(5)])   # <ArrDiff add=[] remove=[]>
Diff(["a", "b"], [Present("a"), Present("c"), Absent("b"), Absent("d")])  # <ArrDiff add=[c] remove=[b]>
Diff(a:Arr, b:Arr, full:Bool=false) Source: stdlib.ngs:3221
Compare arrays. Warning: by default Hash is used so internal Hash keys comparison is used, not ==. Calls Diff(a, b.map(get), full)

Parameters

bArr[ExactPresence]
fullDo not use Hash, work slower but use == comparison.

Returns

Diff
ExitCode(b:Bool) Source: bootstrap.ngs:45
Undocumented

Returns

0 for true, 1 for false
finished_ok(p:Process, field_name:Str, ok:Bool)internal Source: stdlib.ngs:4739
Decide whether a process finished normally.

Example

# 'ok' option is set to true when the value is missing after ':'
$(ok: ls no-such-file)
init(i:FilterIter, upstream_iter:Iter, predicate:Any, invert_predicate:Bool=false) Source: autoload/Iter.ngs:129
EXPERIMENTAL! Do not use!
inspect(b:Bool) Source: stdlib.ngs:5998
Inspect boolean.

Returns

Lines with exactly one line
Int(b:Bool) Source: stdlib.ngs:3336
Convert Bool to int.

Returns

Int

Example

true.Int()   # 1
false.Int()  # 0
not(x:Bool)
Invert boolean
report(tr:TestsResults, group_name:Str, test_name:Str, result:Result, critical:Bool) Source: autoload/TestsResults.ngs:14
Undocumented
Str(b:Bool) Source: stdlib.ngs:3375
Undocumented
Str(t:Time, format:Str='%F %T %Z', gmt:Bool=false) Source: stdlib.ngs:6249
String representation of Time

Parameters

formatstrftime(3) format
gmtUse GMT time zone (defaults to local time zone)
test(results:TestsResults, group:Str, name:Str, f:Fun, critical:Bool=true) Source: autoload/test.ngs:35
EXPERIMENTAL! Do not use! Runs f as a test in a test group
~~(haystack:Str, needle:Str, collect_unmatched:Bool=false) Source: stdlib.ngs:3679
Find all non-overlapping matches of a substring in a string.

Returns

if collect_unmatched - Arr with each element being MatchSuccess or Str, if not collect_unmatched - Arr of MatchSuccess

Example

["key=value", "key2=value2"].map(F(kv) {
  m = kv ~ "="
  [m.before, m.after]
}).Hash()  # {'key': 'value', 'key2': 'value2'}
~~(s:Str, r:RegExp, collect_unmatched:Bool=false) Source: stdlib.ngs:5756
Find all non-overlapping matches of regular expression in a string.

Returns

if collect_unmatched - Arr with each element being MatchSuccess or Str, if not collect_unmatched - Arr of MatchSuccess

Example

("x10ab20c30y" ~~ /[0-9]+/).whole.map(Int).sum()  # 60

arr = (~~)("x10ab20c30y", /[0-9]+/, true)
arr .= map(F(elt) if elt is MatchSuccess "[${elt.whole}]" else elt)
arr.join("")  # "x[10]ab[20]c[30]y"