Eachable2 type

Eachable which each() calls the callback with two arguments

Direct parent types

Eachable
Parent type of all types that have each() method
Direct subtypes: 2

Direct children types

Hash
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.
Direct subtypes: 1
HashLike
Base type for user-defined hash-like types. This is a workaround: it's not possible currently no inherit from the built-in Hash type.
Direct subtypes: 4

Methods

all(e:Eachable2, predicate:Fun) Source: stdlib.ngs:3717
Checks whether all of the key-value pairs satisfies the predicate: predicate(k, v)

Returns

Bool
any(e:Eachable2, predicate:Fun) Source: stdlib.ngs:3702
Checks whether any of the key-value pairs satisfies the predicate: predicate(k, v)

Returns

Bool
apply(x:Eachable2, f:Fun) Source: stdlib.ngs:716
Applies f to arguments in x Same as calling f(**x)
count(e:Eachable2, predicate:Fun) Source: stdlib.ngs:3900
Count number of key-value pairs in Hash that satisfy the predicate.

Parameters

eSomething to check, typically a Hash
predicateTest function to be called with one key and one value at a time: predicate(k, v)

Returns

Int

Example

{'a': 1, 'b': 2, 'c': 11}.count(F(k, v) v>10)  # 1
fields(e:Eachable2, pattern:Any) Source: stdlib.ngs:3928
Only keep fields matching the pattern. Same as e.filterk(pattern). In some other languages, similar functionality is called "project".

Example

{"a": 1, "b": 2}.fields(AnyOf("a", "a2"))  # {"a": 1}
fields(e:Eachable2, n:Not) Source: stdlib.ngs:3936
Remove fields matching the pattern. Same as e.fields(Not(AnyOf(n.pattern))). In some other languages, similar functionality is called "project".

Parameters

nNot(Arr)

Example

{"a": 1, "b": 2}.fields(Not(%[a c d]))  # {"b": 2}
fields(e:Eachable2, patterns:Arr) Source: stdlib.ngs:3943
Same as e.fields(AnyOf(patterns)) In some other languages, similar functionality is called "project".

Example

{"a": 1, "b": 2}.fields(["a", "a2"])  # {"a": 1}
filterk(h:Eachable2, pattern:Any=method) Source: stdlib.ngs:3845
Filter hash by keys, keeping matched

Example

{"a": 1, "b": 2, "ccc": 3}.filterk(/^.$/)    # {a=1, b=2}
{"aa": 1, "ab": 2, "ba": 3}.filterk(/^a/)    # {aa=1, ab=2}
{"aa": 1, "ab": 2, 10: 3}.filterk(Int)       # {10=3}
{10: "a", 20: "b", 30: "c"}.filterk(X > 10)  # {20=b, 30=c}
filterv(h:Eachable2, pattern:Any=method) Source: stdlib.ngs:3860
Filter hash by values

Example

{"a1": 1, "a2": 2, "b1": 10}.filterv(X>5)  # {"b1": 10}
init(c:_Cell, val:Eachable2)
An Eachable2 value is a table cell with all pairs one below the other. Converts values to strings using _Cell().
partitionk(something:Eachable2, pattern:Any=method) Source: stdlib.ngs:3880
Undocumented
partitionv(something:Eachable2, pattern:Any=method) Source: stdlib.ngs:3885
Undocumented
rejectk(h:Eachable2, pattern:Any=method) Source: stdlib.ngs:3852
Filter hash by keys, removing matched. See filterk().

Example

{"a1": 1, "a2": 2, "b1": 10}.rejectk(/^b/)  # {"a1": 1, "a2": 2}
rejectv(h:Eachable2, pattern:Any=method) Source: stdlib.ngs:3866
Filter hash by values
without(e:Eachable2, without_k:Any)deprecated Source: stdlib.ngs:4054
Filter out specific key. Deprecated. Use rejectk() or fields(Not(...)).

Parameters

eSource
without_kThe key to filter out

Example

{'a': 1, 'b': 2, 'c': 3}.without('a')  # {'b': 2, 'c': 3}
without(e:Eachable2, without_k:Any, without_v:Any)deprecated Source: stdlib.ngs:4066
Filter out specific key-value pair. Deprecated. Use reject().

Parameters

eSource
without_kThe key to filter out
without_vThe value to filter out

Example

{'a': 1, 'b': 2, 'c': 3}.without('a', 1).without('b', 22)  # {'b': 2, 'c': 3}