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(udm:UserDefinedMethod) Source: stdlib.ngs:491
Undocumented

Returns

true
Bool(mm:MultiMethod) Source: stdlib.ngs:508
Whether MultiMethod has any methods
Bool() Source: stdlib.ngs:571
Make false

Returns

false
Bool(s:Success) Source: stdlib.ngs:1090
Convert Success to Bool (true)

Returns

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

Returns

false
Bool(ms:MatchSuccess) Source: stdlib.ngs:1134
Undocumented

Returns

true
Bool(mf:MatchFailure) Source: stdlib.ngs:1140
Undocumented

Returns

false
Bool(al:ArrLike) Source: stdlib.ngs:2073
Check whether al has any elements.
Bool(a:AnyOf) Source: stdlib.ngs:2146
Checks whether any of the items are truthy.
Bool(a:AllOf) Source: stdlib.ngs:2213
Checks whether all items are truthy.
Bool(hl:HashLike) Source: stdlib.ngs:2279
Check whether hl has any elements.

Returns

Bool
Bool(s:Set) Source: stdlib.ngs:2421
Check whether the set is not empty
Bool(r:Real) Source: stdlib.ngs:2628
Undocumented
Bool(fb:FullBox) Source: stdlib.ngs:4521
Always true
Bool(eb:EmptyBox) Source: stdlib.ngs:4524
Always false
Bool(d:ArrDiff) Source: stdlib.ngs:4913
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:4949
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:6155
Checks whether the path is accessible using access(2) and F_OK.

Returns

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

Example

if File("myfile.txt") ...
if Dir("my_tmp_dir") ...
Bool(p:Program) Source: stdlib.ngs:6454
Checks whether the given program is found in path.

Returns

Bool. The program is found in path or program name is absolute
Bool(pp:ProcessesPipeline) Source: stdlib.ngs:6996
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(t:Time) Source: stdlib.ngs:9009
Undocumented
Bool(rd:ResDef) Source: autoload/globals/Res.ngs:106
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/globals/Iter.ngs:126
EXPERIMENTAL! Do not use!
Bool(i:FilterIter) Source: autoload/globals/Iter.ngs:175
EXPERIMENTAL! Do not use!
Bool(i:FunIter) Source: autoload/globals/Iter.ngs:222
EXPERIMENTAL! Do not use!
Bool(i:ConstIter) Source: autoload/globals/Iter.ngs:237
Convert ConstIter to Bool (true).

Returns

true
Bool(i:RangeIter) Source: autoload/globals/Iter.ngs:276
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/globals/Iter.ngs:302
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/globals/Iter.ngs:344
Check whether there are more pairs to iterate over.

Returns

Bool. true: next() will return next pair. false: next() will throw NoNext
Bool(ri:RecIter) Source: autoload/globals/Iter.ngs:416
Undocumented
Bool(t:Table) Source: autoload/globals/Table.ngs:104
Check whether there are any rows in the table.
Bool(t:Table) Source: autoload/globals/Table2.ngs:244
Check whether there are any rows in the table.
Bool(d:Description)
Undocumented
Bool(t:Terminal) Source: autoload/globals/Terminal.ngs:46
Undocumented
Bool(t:NoTerminal) Source: autoload/globals/NoTerminal.ngs:8
Undocumented

Methods

==(a:Bool, b:Bool)
Compare booleans
code(b:Bool) Source: stdlib.ngs:4959
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:4833
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:4863
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:4890
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: stdlib.ngs:191
Undocumented

Returns

0 for true, 1 for false
finished_ok(p:Process, field_name:Str, ok:Bool)internal Source: stdlib.ngs:6906
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(dv:DynVar, cross_require:Bool=false) Source: stdlib.ngs:5835
DynVar constructor
Int(b:Bool) Source: stdlib.ngs:5033
Convert Bool to int.

Returns

Int

Example

true.Int()   # 1
false.Int()  # 0
JsonData(b:Bool) Source: stdlib.ngs:4962
Convert Bool into JSON compatible data structure - boolean
not(x:Bool)
Invert boolean
report(tr:TestsResults, group_name:Str, test_name:Str, result:Result, critical:Bool) Source: autoload/globals/TestsResults.ngs:11
Undocumented
Str(b:Bool) Source: stdlib.ngs:5077
Undocumented
Str(t:Time, format:Str='%F %T %Z', gmt:Bool=false) Source: stdlib.ngs:8992
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/globals/test.ngs:32
EXPERIMENTAL! Do not use! Runs f as a test in a test group
~~(haystack:Str, needle:Str, collect_unmatched:Bool=false) Source: stdlib.ngs:5458
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
~~(s:Str, r:RegExp, collect_unmatched:Bool=false) Source: stdlib.ngs:8340
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"