Hash type

Hash type. Maps unique keys to their values. Key-Value pairs are stored and iterated in insertion order. Currently Hash type has several limitations: Hash keys are hashed using internal hash() function which can not be overwritten. The internal hash() multimethod exposed to NGS code but adding methods to it or setting "hash" to some other function will not affect operation of Hashes. Hash values are compared using internal is_equal() function which can not be overwritten. Both hash() and is_equal() currently handle only Int, Str and arbitrary objects. Comparison of arbitrary objects is done by comparing their addresses in memory.

Example

x = {"a": 1, "b": 2}
echo(x)
# Output:
#   {a=1, b=2}

echo(x.keys())
# Output:
#   ['a','b']

echo(x.values())
# Output:
#   [1,2]

x = {"a": 1, "b": 2}
x.a = 10
echo(x)
# Output:
#   {a=10, b=2}

Direct parent types

Eachable2
Eachable which each() calls the callback with two arguments
Direct subtypes: 2

Direct children types

Namespace
Namespace type. Returned by 'ns' keyword. Inherits and functions mostly as Hash.

Constructors

Hash(obj:NormalTypeInstance)
Get all fields and their values as key-value pairs in the resulting Hash.

Returns

Hash

Example

(1..10).Hash()  # Hash {start=1, end=10, step=1}
Hash() Source: stdlib.ngs:577
Make empty hash

Returns

{}
Hash(h:Hash) Source: stdlib.ngs:939
Undocumented

Returns

h
Hash(hl:HashLike) Source: stdlib.ngs:2317
Get the underlying Hash with all the keys/values of the HashLike. Note: the returned value is not a copy.

Returns

Hash
Hash(arr:Arr) Source: stdlib.ngs:4256
Create a Hash from Arr of Arr[2]

Parameters

arrArray of Arrays. Each one of the sub-arrays must have exactly two elements.

Returns

Hash

Example

Hash([['a', 1], ['c', 3]])  # {'a': 1, 'c': 3}
Hash(e:Eachable1, field:Str) Source: stdlib.ngs:4270
Create Hash with keys being the given field of elements and the values being corresponding elements.

Returns

Hash

Example

Hash([{'x': 1}, {'x': 2}], 'x')  # {1: {'x': 1}, 2: {'x': 2}}
Hash(e:Eachable1, cb:Fun) Source: stdlib.ngs:4281
Create a Hash from keys in Eachable1 using cb for values calculation

Parameters

eKeys of the hash to build
cbFunction to be called with one key at a time. Should calculate a value for the given key.

Returns

Hash

Example

Hash([1,2], F(x) x*2)  # {1: 2, 2: 4}
Hash(keys:Arr, values:Arr) Source: stdlib.ngs:4293
Create a Hash from keys in "keys" and corresponding values in "values"

Parameters

keysKeys for the new Hash
valuesValues for the new Hash

Returns

Hash

Example

Hash(["a", "b", "c"], [1,2,3])  # {"a": 1, "b": 2, "c": 3}
Hash(e:Eachable1, key_field:Str, val_field:Str) Source: stdlib.ngs:4305
Create Hash from Arr of something that has key and value fields

Parameters

eEachable1 with all the keys and values
key_fieldName of the field holding the keys of newly created Hash
val_fieldName of the field holding the values of newly created Hash

Returns

Hash

Example

Hash([{"Name": "n1", "Value": "v1"},{"Name": "n2", "Value": "v2"}], "Name", "Value")  # {"n1": "v1", "n2": "v2"}
Hash(e:Eachable1)experimental Source: stdlib.ngs:4314
Undocumented

Methods

+(a:Hash, b:Hash) Source: stdlib.ngs:4361
Add Hashes. Builds new hash with key-value pairs from both a and b. If same key is present in both a and b, the value from b is used.

Returns

Hash

Example

{'a': 1, 'b': 2, 'c': 3} + {'b': 20, 'd': 40}  # {'a': 1, 'b': 20, 'c': 3, 'd': 40}
.(h:Hash, field:Str) Source: stdlib.ngs:944
Get hash key.

Example

h = {"a": 1}
h.a  # 1, Same as h["a"]
.=(h:Hash, field:Str, v:Any) Source: stdlib.ngs:950
Set hash key.

Returns

v

Example

h = {"a": 1}
h.a = 2  # 2, Same as h["a"] = 2
::(h:Hash, k:Any) Source: stdlib.ngs:451
Get Hash key. Useful when calling method stored in a Hash key. Useful for working with namespaces, which are implemented as Hash instances.

Example

elb = AWS::Elb(...).converge(...)
::=(h:Hash, k:Any, v:Any) Source: stdlib.ngs:456
Set Hash key. It's implemented to complete the :: operator. There is no particular use case.
==(a:Hash, b:Hash) Source: stdlib.ngs:3948
Compare two Hashes. Hashes must have same keys with same values in same order to return true. Both hashes must not be modified during comparison. This was not tested.

Returns

Bool
=~(x:Any, h:Hash, mc:MatchContext) Source: stdlib.ngs:1368
Checks whether object fields (or Hash keys) named after h keys match (=~) the corresponding h values. Key of type Str, Int or Real: the field must exist (unless the value is IfExists) and match. Key that is a pattern (other than Branch or Each): some field whose name matches the key must match. Key that is Each(pattern): every field whose name matches the pattern must match. Key that is Branch(pattern): every field whose name matches the pattern is tried, always matches. Inspired by underscorejs' "matcher"
[](h:Hash, k:Any)
Get hash value by key. Throws KeyNotFound.

Returns

Any

Example

h = {"a": 1}
h["a"]  # 1
h["b"]  # KeyNotFound exception thrown
[]=(h:Hash, k:Any, v:Any)
Set hash value.

Parameters

hTarget hash
kKey
vValue

Returns

v

Example

h = {"a": 1}
h["a"] = 2
h["a"]  # 2
[]=(h:Hash, k:Any, v:Any)
Setting same key twice is a bug. If it happens, augment_types() works on one objects but other objects are used later.
\(name:Str, attributes:Hash, children:Arr)experimental Source: stdlib.ngs:9456
Undocumented

Automatically called by NGS for syntax

\name attr1=val1 attr2=val2 ... [ ... ]
Argv(h:Hash) Source: stdlib.ngs:7231
Convert a Hash, describing command line arguments, to array of strings, appropriate for using as argument to external process. Key-value pairs with values of type NoData (null, EmptyBox) are discarded. Key-value pairs with empty array values are discarded. Values of type Box are unboxed. For keys which are arrays of two elements, Bool value selects first (for true) or second (for false) element. For keys which are arrays of a single element, Bool value selects whether the key is present or absent in the output. For keys which are Repeat, Eachable1 value causes the switch to be repeated for each element, building switch name and switch value pairs.

Example

# Typical usage:
argv = Argv({'name1': value1, 'name2': value2, ...})
$(my_command $*argv)
# Handling of key-value pairs
Argv({"--a": 1, "-b": null})                         # ['--a', 1]
Argv({["-y1", "-n1"]: true, ["-y2", "-n2"]: false})  # ['-y1', '-n2']
Argv({["-y3"]: true, ["-y4"]: false})                # ["-y3"]
Argv({Repeat("--repeat"): ["a", "b"]})               # ["--repeat", "a", "--repeat", "b"]
Argv({"-a1": [], "-a2": [1,2,3]})                    # ["-a2", 1, 2, 3]
Arr(h:Hash) Source: stdlib.ngs:3549
Make Arr from Hash. Each key/value pair becomes two-items array.

Returns

Arr of form [[k1, v1], [k2, v2], ...]

Example

Arr({'x': 7, 'y': 8})  # [['x', 7], ['y', 8]]
assert_hash_keys_values(actual:Any, expected:Hash, title:Str='Must be a hash with keys and values') Source: autoload/globals/test.ngs:143
Assert actual is a Hash and it has the expected keys with expected values. Throws TestFail.

Returns

actual

Example

assert_hash_keys_values({'kk': 7}, {'ll': 7})  # Throws TestFail
assert_hash_keys_values({'kk': 7, 'll': 8}, {'kk': 7})  # OK
Box(h:Hash, k:Any) Source: stdlib.ngs:4648
Convert hash value indexed by the given key to a Box

Parameters

kkey to look in hash

Returns

Box. FullBox if the hash has the element referenced by k, EmptyBox otherwise.

Example

my_hash = {"a": 10, "b": 300}
my_hash.Box("a").map(X*2).each(echo)
# output: 20
my_hash.Box("nope").map(X*2).each(echo)
# no output
code(h:Hash) Source: stdlib.ngs:4422
Convert a Hash to NGS code that would produce the given Hash when executed. Not fully functional yet.

Returns

Str
collector(h:Hash, body:Fun) Source: stdlib.ngs:3027
Defines collector { ... collect(...) ... } behaviour for hashes

Parameters

hInitial hash
bodyThe body after collector keyword and initial value, wrapped in a function "collector/{'my': 'hash'} THIS_CODE"

Returns

Constructed Hash

Example

arr = [{"Name": "n1", "Value": "v1"},{"Name": "n2", "Value": "v2"}]
my_hash = collector/{}
	arr.each(F(elt) collect(elt.Name, elt.Value))
echo(my_hash)  # Outputs: {n1=v1, n2=v2}
copy(h:Hash) Source: stdlib.ngs:4414
Make shallow copy of a Hash

Returns

Hash
created(rd:ResDef, resources:Arr, props:Hash) Source: autoload/globals/Res.ngs:200
Called by create() on new resources. Appends the new resources to the list and runs update(). Don't call directly.

Parameters

resourcesArr of Res
decode(s:Str, hints:Hash={}) Source: stdlib.ngs:7699
Attempt to decode JSON. Uses decode_json().
decode(s:Str, hints:Hash={}) Source: stdlib.ngs:7706
Detects single line, no whitespace, scheme://...

Returns

URL

Example

"https://example.com/a".decode().host  # "example.com"
decode(s:Str, hints:Hash) Source: stdlib.ngs:7727
EXPERIMENTAL. KVS (key-value separator) hint for decode()

Example

decode('a b\nc d', {'KVS': ' '}) == {'a': 'b', 'c': 'd'}
decode(s:Str, hints:Hash) Source: stdlib.ngs:7736
EXPERIMENTAL. FS (field separator) hint for decode()

Example

decode('a b\nc d', {'FS': ' '})  # [['a', 'b'], ['c', 'd']]
decode(s:Str, hints:Hash) Source: stdlib.ngs:7746
EXPERIMENTAL! Do not use! Handle fields_names hint - run decode() and make Arr[Hash] from Arr[Arr] using provided fields_names

Example

backup_list = fetch('backup.list', {'FS': ' ', 'fields_names': %[env role]})
decode(s:Str, hints:Hash) Source: stdlib.ngs:7756
Decode "curl -i" to {"code": Int, "message": Str, "headers": Hash, "headers_arr": Hash, "body": Str} .body is not recursively decoded

Returns

Hash
decode(s:Str, hints:Hash) Source: stdlib.ngs:7856
Parse the output of "aws" command. Extracts the array (see "s" below"). For "describe-instances", flattens the instance list.

Parameters

sStr containing JSON with a Hash at top level with exactly one Arr as value
hintshints.process.command.argv[0] must be 'aws'

Returns

data structure, typically an Arr at top level. If s is empty string - null.
decode(s:Str, hints:Hash) Source: stdlib.ngs:8026
Parse the output of "find" command which does not use "-printf". Handles "-print0".

Parameters

hintshints.process.command.argv[0] must be 'find'

Returns

Arr of Str
decode(s:Str, hints:Hash) Source: stdlib.ngs:8037
Parse the output of "locate" command.

Parameters

hintshints.process.command.argv[0] must be 'locate'

Returns

Arr of Str
decode(s:Str, hints:Hash={}) Source: stdlib.ngs:9655
Decodes JSON Web Token (JWT)
deeper(mc:MatchContext, new_fields:Hash, cb:Fun) Source: stdlib.ngs:1174
Undocumented
del(h:Hash, k:Any)
Delete hash key. Throws KeyNotFound if k is not in h. WARNING: this method will probably be renamed to "delete" in future versions.

Parameters

hTarget hash
kKey

Returns

h

Example

h={"a": 1}; h.del("a"); h  # {}
h={}; h.del("a"); # KeyNotFound exception
h={"a": 1, "b": 2}; h.del("a"); h  # {"b": 2}
dflt(h:Hash, k:Any, v:Any) Source: stdlib.ngs:4430
Set a key in a Hash if it's not already set

Parameters

vThe value to set when k is not in h. If v is a Fun, v(k) is set instead, only when k is not in h.

Returns

Hash value, the already-existed or new.

Example

my_hash.dflt(k, []).push(elt)
Diff(a:Hash, b:Hash) Source: stdlib.ngs:4924
Compare hashes

Example

diff = Diff(current_tags, target_tags)
if (tags = AWS::cli_tags(diff.add + diff.change)) {
	r.run('update_tags/add', %(aws ec2 create-tags --resources ${r.id()} --tags $*tags))
}
if (tags = diff.remove / "Key=$X") {
	r.run('update_tags/remove', %(aws ec2 delete-tags --resources ${r.id()} --tags $*tags))
}
each(h:Hash, cb:Fun) Source: stdlib.ngs:3981
Iterate a Hash.

Parameters

hHash to iterate
cbFunction to call with successive keys and values

Returns

h

Example

{"a": 1, "b": 2}.each(F(k, v) echo("$k=$v"))  # Outputs: "a=1" and on the next line "b=2"
each_idx_key_val(h:Hash, cb:Fun) Source: stdlib.ngs:4041
Iterate a Hash.

Parameters

hHash to iterate
cbFunction to call with successive indexes, keys and values

Returns

h

Example

{"a": 1, "b": 2}.each_idx_key_val(F(idx, k, v) echo("[$idx] $k=$v"))
# Outputs: "[0] a=1" and on the next line "[1] b=2"
eachk(h:Hash, cb:Fun) Source: stdlib.ngs:4020
Iterate a Hash.

Parameters

hHash to iterate
cbFunction to call with successive keys

Returns

h
eachv(h:Hash, cb:Fun) Source: stdlib.ngs:4028
Iterate a Hash.

Parameters

hHash to iterate
cbFunction to call with successive values

Returns

h
echo_cli(h:Hash)experimental Source: stdlib.ngs:9765
Echo the value before exiting the program, when the value is a result of evaluating the whole program. Only works with TTY. Prints each key-value pair as "K: V" on its own line.
encode(data:Any, hints:Hash={}) Source: stdlib.ngs:7772
Encode data as JSON if hints say that "filename" ends with ".json"

Returns

Str
encode_json(x:Any, hints:Hash={}) Source: stdlib.ngs:9357
Convert data structure into JSON compatible data using JsonData and call built-in encode_json(). Implement JsonData() for your own types to customize converting to JSON.

Parameters

hintsHash, set 'pretty' to true to pretty-print the JSON

Returns

Str
exec(argv:Arr, env:Hash=ENV) Source: stdlib.ngs:7281
Call EXECVE(2)
exec(prog:Str, argv:Arr=[], env:Hash=ENV) Source: stdlib.ngs:7288
Call EXECVE(2)

Parameters

argvargv, without the program
exec(prog:Str, env:Hash=ENV) Source: stdlib.ngs:7292
Call EXECVE(2)
fetch(filename:Str, decode_hints:Hash={}) Source: stdlib.ngs:6802
read() and decode() the given file

Example

fetch("1.json")  # Data structure, the parsed JSON
fetch(url:Str, decode_hints:Hash={}) Source: stdlib.ngs:6810
Fetch HTTP(S) file and decode() it

Example

fetch('https://api.myip.com')  # Data structure, the parsed JSON
fetch(decode_hints:Hash={}) Source: stdlib.ngs:6817
Read standard input and decode() it, passing "source" equals "stdin" hint.

Example

fetch()  # Data structure, parsed stdin
fetch(p:Path, decode_hints:Hash={}) Source: stdlib.ngs:6821
read() and decode() the given file

Example

fetch(File("1.json"))  # Data structure, the parsed JSON
fetch(f:MaybeFile, decode_hints:Hash={}, dflt:Any=null) Source: autoload/globals/MaybeFile.ngs:17
Fetches the file using previously defined fetch()

Returns

Like fetch(File, ...) or dflt if the file is not present.
filter(h:Hash, predicate:Fun) Source: stdlib.ngs:4115
Filter a hash. Build new hash with kev-value pairs selected by the given predicate.

Parameters

hSource hash
predicateTest function to be called with one key and one value at a time: predicate(k, v)

Example

{'a': 1, 'b': 2}.filter(F(k, v) k == 'a')  # {'a': 1}
get(h:Hash, k:Any, dflt:Any)
Get hash value by key or dflt if it does not exist

Returns

Any

Example

h = {"a": 1}
h.get("a", 10)  # 1
h.get("b", 10)  # 10
get(h:Hash, k:Any, dflt:Any=null) Source: stdlib.ngs:953
Get hash value by key or Value(dflt, k) if it does not exist

Parameters

dfltDefault value, defaults to null. If dflt is a Fun, the result of dflt(k) is used instead.

Returns

h[k] or Value(dflt, k)

Example

h = {"a": 1}
h.get("a")  # 1
h.get("b")  # null
h.get("b", 10)  # 10
h.get("b", { 10 })  # 10
in(x:Any, h:Hash)
Check key presence in a Hash

Returns

Bool

Example

"a" in {"a": 1}  # true
"b" in {"a": 1}  # false
init(h:Hash) Source: stdlib.ngs:298
Trivial initialization helper for init(o, ...) Sets object fields from the supplied parameters

Example

# sets t.a and t.b
F init(t:MyType, a, b) init(args())
init(hl:HashLike, h:Hash=null) Source: stdlib.ngs:2309
Create a HashLike.

Parameters

hIf provided, used as initial value.

Example

HashLike(%{a aha b bee}) # <HashLike a=aha b=bee>
init(hl:DeprecatedTopLevelHashlike, deprecated_field:Any, h:Hash=null) Source: stdlib.ngs:2374
Create a HashLike.

Parameters

hIf provided, used as initial value.

Example

HashLike(%{a aha b bee}) # <HashLike a=aha b=bee>
init(i:HashIter, h:Hash) Source: autoload/globals/Iter.ngs:333
HashIter constructor.

Example

i = HashIter({"a": 1, "b": 2})
init(r:Res, def:ResDef, props:Hash) Source: autoload/globals/Res.ngs:123
Stores def and props in r
init(rd:AWS::ResDef, _ngs_tags:Hash) Source: autoload/globals/AWS.ngs:183
Initialize ResDef from _ngs_tags. Sets .regions to null and .Tags to _ngs_tags.
init(rd:AWS2::ResDef, _ngs_tags:Hash) Source: autoload/globals/AWS2.ngs:201
Initialize ResDef from _ngs_tags. Sets ._Region to null and .Tags to _ngs_tags.
init(pmy:ParamsMatchY, args:Arr, kwargs:Hash) Source: autoload/globals/ArgvMatcher.ngs:12
Undocumented
init(t:Table, row_hash:Hash) Source: autoload/globals/Table2.ngs:180
Create single-line table
init(mp:MethodParam, h:Hash) Source: autoload/globals/MethodParam.ngs:21
Initialize MethodParam from params() array element
init(nd:NamespaceDescription, namespace:Hash)
Undocumented
init(nd:NamespaceDescription, containing_nd:NamespaceDescription, name:Str, namespace:Hash)
Undocumented
Iter(h:Hash) Source: autoload/globals/Iter.ngs:328
Undocumented
JsonData(h:Hash) Source: stdlib.ngs:4331
Convert Hash into JSON compatible data structure - object
keys(h:Hash)
Get Hash keys as an array

Returns

Arr

Example

{"a": 1, "b": 2}.keys()  # ['a','b']
len(h:Hash)
Get number of key-value pairs in a Hash

Returns

Int

Example

{"a": 1, "b": 2}.len()  # 2
limit(h:Hash, l:Int) Source: stdlib.ngs:4383
Truncate a Hash if necessary so it would have maximum l key-value pairs.

Parameters

hSource hash
lMaximum elements

Returns

Hash

Example

{"a": 1, "b": 2}.limit(1)  # {"a": 1}
ll_hash_head(h:Hash)
Low level. Do not use directly.

Returns

LLHashEntry or null
ll_hash_tail(h:Hash)
Low level. Do not use directly.

Returns

LLHashEntry or null
map(h:Hash, mapper:Fun) Source: stdlib.ngs:4053
Map a Hash

Parameters

hHash with source keys and values
mapperFunction to be called with keys and values from h

Returns

Arr

Example

{'a': 1, 'b': 2}.map(F(k, v) "${k}-$v")  # ['a-1', 'b-2']
map_idx_key_val(h:Hash, mapper:Fun) Source: stdlib.ngs:4063
Map a Hash

Parameters

hHash with source keys and values
mapperFunction to be called with sequential zero-based index, keys and values from h

Returns

Arr

Example

{'a': 1, 'b': 2}.map_idx_key_val(F(i, k, v) "${i}-${k}-$v")  # ['0-a-1', '1-b-2']
mapk(h:Hash, mapper:Fun) Source: stdlib.ngs:4072
Map Hash keys. Build new Hash with same values as in h but keys mapped by mapper.

Parameters

hSource hash
mapperFunction to be called with keys

Returns

Hash

Example

mapk({"a": 1}, F(k) k+"z")  # {"az": 1}
mapkv(h:Hash, mapper:Fun) Source: stdlib.ngs:4103
Map Hash keys and values. Build new Hash with keys and values mapped by mapper.

Parameters

hSource hash
mapperFunction to be called with keys and values

Example

mapkv({"a": 1}, {[A+"zz", B+10]})  # {"azz": 11}
mapv(h:Hash, mapper:Fun) Source: stdlib.ngs:4091
Map Hash values. Build new Hash with same keys as in h but values mapped by mapper.

Parameters

hSource hash
mapperFunction to be called with values

Returns

Hash

Example

LEN = 3
lines_ = read("/usr/share/dict/words").lines()
long_lines = lines_.filter({A.len()>LEN})
prefix_to_lines = long_lines.group(F(line) line[0..LEN])  # {"pfx1": ["pfx1a", "pfx1b", ...], "pfx2": ["pfx2a", "pfx2b", ...], ...}
prefix_to_count = prefix_to_lines.mapv(len)  # {"pfx1": 30, "pfx2": 35, ...}
top = prefix_to_count.Arr().sort(F(a, b) b[1] <= a[1]).Hash()
top .= limit(10)
echo(top)  # Outputs: {con=1219, dis=1001, pro=808, pre=607, com=600, int=543, tra=498, ove=431, per=422, imp=421}
opt_prop(rd:ResDef, name:Str, props:Hash) Source: autoload/globals/Res.ngs:210
Get optional resource property, looking up in properties first and then in anchor.

Returns

Box
opt_prop(rd:ResDef, name:Str, props:Hash, cb:Fun) Source: autoload/globals/Res.ngs:213
Run cb with optional resource property if it exists, uses opt_prop(ResDef, Str, Hash)
push(t:Table, row_hash:Hash) Source: autoload/globals/Table.ngs:74
Append given row to the table

Returns

t
reject(h:Hash, predicate:Fun) Source: stdlib.ngs:4125
h.filter(not + predicate)
req_prop(rd:ResDef, name:Str, props:Hash) Source: autoload/globals/Res.ngs:217
Get resource property, looking up in properties first and then in anchor
shift(h:Hash, k:Any) Source: stdlib.ngs:4451
Get the given key from a Hash and remove it from the Hash. Underlying h[k] may throw KeyNotFound.

Example

h = {"a": 1}
s = h.shift("a")  # h == {} and s == 1
shift(h:Hash, k:Any, dflt:Any) Source: stdlib.ngs:4459
Get a key from a Hash and remove it from the Hash. If the key is not in the Hash, return Value(dflt, k)

Parameters

dfltDefault value. If dflt is a Fun, the result of dflt(k) is used instead.

Example

h = {}
h.shift("a", 7)  # 7
sort(h:Hash, lte:Fun=method) Source: stdlib.ngs:4436
Sort a Hash.

Parameters

lteLess-then-or-equal function to use for comparison of the keys in h

Returns

Hash

Example

{"b": 2, "c": 3, "a": 1}.sort()  # {"a": 1, "b": 2, "c": 3}
sortk(h:Hash, lte:Fun=method) Source: stdlib.ngs:4196
Sort Hash by keys

Returns

Hash

Example

{'b': 2, 'c': 11, 'a': 1}.sortk()  # {'a': 1, 'b': 2, 'c': 11}
sortv(h:Hash, lte:Fun=method)experimental Source: stdlib.ngs:4204
Undocumented
stdlib_aws_straighten_tags(h:Hash) Source: stdlib.ngs:7833
Do not use directly. Subject to change. Convert "Tags" array in the given AWS resource (typically returned by AWS CLI) into Hash.

Example

t = {"Tags": [{"Key": "k", "Value": "v"},{"Key": "k2", "Value": "v2"}]}  # Not very convenient, is it?
t.stdlib_aws_straighten_tags()
t  # {Tags={k=v, k2=v2}}
store(filename:Str, data:Any, encode_hints:Hash={}) Source: stdlib.ngs:6825
encode() and write() the data to the file

Returns

null (but subject to change)
store(file:File, data:Any, encode_hints:Hash={}) Source: stdlib.ngs:6832
encode() and write() the data to the file
store_to(data:Any, target:Any, encode_hints:Hash={}) Source: stdlib.ngs:6835
Same as store(target, data, encode_hints)
Str(h:Hash) Source: stdlib.ngs:5085
Convert Hash to string

Returns

Str
Strs(h:Hash) Source: stdlib.ngs:4374
Build array of Str where each resulting string is of the form "KEY=VALUE"

Parameters

hSource hash

Returns

Arr of Str

Example

{'a': 1, 'b': 2}.Strs()  # ['a=1', 'b=2']
subset(smaller:Hash, larger:Hash) Source: stdlib.ngs:3963
Undocumented
tr(x:Any, h:Hash, tc:TrContext) Source: autoload/globals/tr.ngs:138
Match / transform x using the pattern in h.

Parameters

xHash or HashLike

Returns

Lit or TrCommand
update(dst:Hash, src:Hash)
Update a Hash with key-value pairs from another Hash. For non destructive version use "dst + src".

Returns

dst

Example

{"a": 1, "b": 2}.update({"b": 10, "c": 20})  # {a=1, b=10, c=20}
update(r:AWS::VpcRes, props:Hash)internal Source: autoload/globals/AWS.ngs:284
Declarative primitive for updating AWS VPC resources
update(r:AWS::IgwRes, props:Hash)internal Source: autoload/globals/AWS.ngs:358
Declarative primitive for creating AWS InternetGateway resources
update(r:AWS::RouteTableRes, props:Hash)internal Source: autoload/globals/AWS.ngs:433
Declarative primitive for updating AWS RouteTable resources
update(sg:AWS::SecGroupRes, props:Hash)internal Source: autoload/globals/AWS.ngs:588
Declarative primitive for updating AWS Security Group resources
update(r:AWS::SubnetRes, props:Hash)internal Source: autoload/globals/AWS.ngs:673
Declarative primitive for updating AWS Subnet resources
update(r:AWS::InstanceRes, props:Hash)internal Source: autoload/globals/AWS.ngs:855
Declarative primitive for updating AWS Instance resources
update(elb:AWS::ElbRes, props:Hash)internal Source: autoload/globals/AWS.ngs:1127
Declarative primitive for updating AWS Elastic Load Balancer resources
update(rrset:AWS::RecordSetRes, props:Hash)internal Source: autoload/globals/AWS.ngs:1337
Declarative primitive for updating AWS Route53 RecordSet resources
update(r:AWS2::Res, orig_props:Hash) Source: autoload/globals/AWS2.ngs:416
Undocumented
update(sg:AWS2::SecGroupRes, props:Hash)internal Source: autoload/globals/AWS2.ngs:665
Declarative primitive for updating AWS Security Group resources
update(r:AWS2::SubnetRes, props:Hash)internal Source: autoload/globals/AWS2.ngs:751
Declarative primitive for updating AWS Subnet resources
update(r:AWS2::InstanceRes, props:Hash)internal Source: autoload/globals/AWS2.ngs:948
Declarative primitive for updating AWS Instance resources
update(elb:AWS2::ElbRes, props:Hash)internal Source: autoload/globals/AWS2.ngs:1223
Declarative primitive for updating AWS Elastic Load Balancer resources
update(z:AWS2::ZoneRes, props:Hash) Source: autoload/globals/AWS2.ngs:1393
Undocumented
update(rrset:AWS2::RecordSetRes, props:Hash)internal Source: autoload/globals/AWS2.ngs:1506
Declarative primitive for updating AWS Route53 RecordSet resources
validate(a:Hash, params_patterns:Hash) Source: stdlib.ngs:426
Validate arguments

Parameters

aArguments, typically args()
params_patternsParameter name -> pattern

Returns

a

Example

F f(x, y) validate(args(), {'x': Int, 'y': { A > 0 }})
values(h:Hash)
Get Hash values as an array

Returns

Arr

Example

{"a": 1, "b": 2}.values()  # [1,2]
AWS::cli_tags(h:Hash) Source: autoload/globals/AWS.ngs:52
Convert hash to Key=...,Value=... strings suitable for passing to AWS CLI.

Returns

Arr of Str

Example

diff = Diff(current_tags, target_tags)
if (tags = cli_tags(diff.add + diff.change)) {
	r.run('add tags', %(aws ec2 create-tags --resources ${r.id()} --tags $*tags))
}
AWS::cli_filters(h:Hash) Source: autoload/globals/AWS.ngs:59
Convert Hash with AWS filters to command line arguments. Key-value pairs in which value is null or an EmptyBox object are discarded. TODO: make it JSON when keys or values contain special characters such as = or ,

Returns

Arr of Str
AWS::cli_tags_filters(h:Hash) Source: autoload/globals/AWS.ngs:70
Convert hash to Name=tag:...,Values=... strings suitable for passing to AWS CLI as filters.

Example

filters = AWS::cli_filters({'vpc-id': ...})
vpcs = ``aws ec2 describe-vpcs --filters $*filters``
AWS::update_tags(r:AWS::Res, props:Hash) Source: autoload/globals/AWS.ngs:127
Don't call directly, use converge(). API subject to change. Update tags using AWS CLI "aws ec2 create-tags" and "aws ec2 delete-tags". The required AWS CLI is computed from current tags, which are expected to be in r.props.Tags, and props.Tags

Returns

Do not count on this value.
AWS2::cli_tags(h:Hash) Source: autoload/globals/AWS2.ngs:52
Convert hash to Key=...,Value=... strings suitable for passing to AWS CLI.

Returns

Arr of Str

Example

diff = Diff(current_tags, target_tags)
if (tags = cli_tags(diff.add + diff.change)) {
	r.run('add tags', %(aws ec2 create-tags --resources ${r.id()} --tags $*tags))
}
AWS2::cli_filters(h:Hash) Source: autoload/globals/AWS2.ngs:59
Convert Hash with AWS filters to command line arguments. Key-value pairs in which value is null or an EmptyBox object are discarded. TODO: make it JSON when keys or values contain special characters such as = or ,

Returns

Arr of Str
AWS2::cli_tags_filters(h:Hash) Source: autoload/globals/AWS2.ngs:70
Convert hash to Name=tag:...,Values=... strings suitable for passing to AWS CLI as filters.

Example

filters = AWS2::cli_filters({'vpc-id': ...})
vpcs = ``aws ec2 describe-vpcs --filters $*filters``
Doc::Transformer(x:Hash) Source: autoload/globals/Doc.ngs:90
Undocumented