Types
Any type is parent type of all types.
All instances in NGS are of type Any.
F(x) ... is same as F(x:Any) ...
Methods
%(x:Any, cb:Fun)
Each operator.
Same as calling x.each(cb)
..(start:Any, end:Any)
Constructs open-open predicate range
..(start:Num, end:Any)
Constructs closed-open numerical range
...(start:Any, end:Any)
Constructs closed-closed predicate range
...(start:Num, end:Any)
Constructs closed-closed numerical range
.=(obj:NormalTypeInstance, attr:Str, v:Any)
Set Normal type (a type that is typically defined by user) instance attribute. Throws AttrNotFound.
/(x:Any, mapper:Fun)
Map operator.
Same as calling x.map(mapper)
?(x:Any, predicate:Fun)
Filter operator.
Same as calling x.filter(predicate)
[](h:Hash, k:Any)
Get hash value by key. Throws KeyNotFound.
\(x:Any, f:Fun)
Call operator.
Same as calling f(x)
all(e:Eachable, predicate:Any)
Check whether all elements in arr satisfy the given predicate.
any(e:Eachable1, predicate:Any)
Check whether there is any element in arr that satisfies the given predicate.
TODO: Make it work on anything with Eachable2 too.
Box(x:Any)
Convert anything to Box (always FullBox)
Box(a:Arr, idx:Any)
Convert array value indexed by the given index
Box(h:Hash, k:Any)
Convert hash value indexed by the given key to a Box
call(r:Return, v:Any=null)
Implements calling of Return type instances
like the finish(i) call in the example below
config(k:Str, v:Any)
Set configuration. To be used with config(k:Str).
count(arr:Arr, predicate:Any)
Count number of items that satisfy the predicate.
TODO: Make it work on anything with each() method.
count(h:Hash, predicate:Any)
Count number of key-value pairs in Hash that satisfy the predicate.
del(h:Hash, k:Any)
Delete hash key. No exception is thrown if key is not found, the deletion is just skipped then.
dflt(arr:Arr, k:Any, v:Any)
Set an attribute on instances if it's not already set
dflt(h:Hash, k:Any, v:Any)
Set an key in a Hash if it's not already set
die(s:Str, exit_code:Any=1)
Write message in s to standard error and exit
dir(dirname:Str, subtype:Any=false)
List directory contents. Warning: "." and ".." are included.
Throws DirFail when directory can not be listed.
dir(dirname:Str, cb:Fun, subtype:Any=false)
List directory contents and call cb with Path() of each found item. Warning: "." and ".." are included.
dump(obj:Any)
Low-level data structure dump. Used for debugging NGS itself.
echo(x:Any)
Echo non-string. Converts x to string first, using Str()
filter(something:Eachable1, predicate:Any)
Filter something to an Arr (array) of values using predicate.
filter(h:Hash, predicate:Any)
Filter hash. Build new hash with kev-value pairs selected by predicate.
first(e:Eachable1, predicate:Any)
Find first element in e that satisfies the predicate.
get(h:Hash, k:Any, dflt:Any)
Get hash value by key or dflt if it does not exist
get(h:Hash, k:Any)
Get hash value by key or null if it does not exist
get(e:Eachable1, attr:Str, dflt:Any)
Return array made of given attribute of each element of given Eachable1 where present or default value where the attribute is not present
Return array (? depends on map() ?) made of given attribute of each element of given Eachable1
glob(pattern:Str, start_dir:Any=.)
Work in progress, do not use!
has(container:Any, element:Any)
Exactly same as "element in container". It's just more convenient in specific cases.
hash(x:Any)
Calculate hash value. Same function that Hash uses internally. Currently Fowler-Noll-Vo (FNV) hash function.
in(x:Any, h:Hash)
Check key presence in a Hash
in(x:Any, arr:Arr)
Checks whether element x is in array arr
index(arr:Arr, predicate:Any)
Find index of first value that satisfies the predicate.
TODO: Make it work on anything with each() method.
indexes(arr:Arr, predicate:Any)
Find all indexes of values that satisfy the predicate
TODO: Make it work on anything with each() method
init(t:Table, name:Any=null)
Initialize rows to an empty array
init(t:Table, name:Any, rows_hashes:Arr)
Create named table containing provided rows
is(obj:Any, t:Type)
Check whether obj is of type t. Uses same function that is used for matching arguments with method parameters when calling a method.
is not(a:Any, b:Any)
"is not" operator. Exactly same as "not(a is b)".
map_base_idx(base:Any, n:Int, mapper:Fun)
EXPERIMENTAL!
Map when there is more than one element. If there is exactly one element, it's left as is
match(a:Any, b:Any)
Used by match EXPR { ... } construct.
not(x:Any)
Boolean negation for non-boolean values. Converts to boolean first.
not in(a:Any, b:Any)
"not in" operator. Exactly same as "not(a in b)"
only(predicate:Any, mapper:Fun)
Transform mapper to handle only items matching predicate. Non-matching items will be returned as is.
Pfx(val:Any)
Convenience method for creating MustPfx
Pred(anything:Any)
Convert anything to a predicate.
rand(something:Any, n:Int)
Pick n elements from something. Uniqueness of picked elements is not guaranteed.
rand_uniq(something:Any, n:Int)
Pick n random unique elements from something
reduce(something:Eachable1, start:Any, f:Fun)
Combine items to a single value using the supplied binary function
First f is applied to start and the first element of something
then on each step f is applied to previous result and next element
of something.
reject(something:Eachable, predicate:Any)
Filter something to an Arr (array) of values using predicate
replace(dst:Any, src:Any)
DISCOURAGED. Replace one object with another. dst and src must be of the same type.
retry(times:Int=60, sleep:Any=1, logger:Fun=(a function), success_predicate:Any=(a function), catch_exceptions:Bool=true, title:Any=<retry>, progress_cb:Fun=(a function), success_cb:Fun=(a function), fail_cb:Any=null, body:Fun=(a function))
Retry. Executes given "body" "times" times. Throws RetryFail if all calls fail and fail_cb is not provided.
SafeStr(val:Any)
Don't use, subject to change, including name
set(obj:Any, attr:Str, val:Any)
Sets the given attribute to the given value
Sfx(val:Any)
Convenience method for creating MustSfx
shift(h:Hash, k:Any)
Get the given key from a Hash and remove it from the Hash.
Underlying h[k] may throw KeyNotFound.
shift(h:Hash, k:Any, dflt:Any)
Get a key from a Hash and remove it from the Hash.
If they key is not in the Hash, return dflt
Str(x:Any, target_width:Int)
Convert anything to Str of a given width
sum(something:Any)
Calculate sum of the elements
the_one(something:Eachable1, predicate:Any)
Find the only element that satisfies the predicate.
Throws TheOneFail exception if there are no elements that satisfy the predicate or if there is more than one element that satisfies the predicate.
the_one(something:Eachable1, predicate:Any, body:Fun, found_more:Fun=(a function), found_none:Fun=(a function))
Find the only element that satisfies the predicate and execute given code with the value
Type(name:Str, doc:Any)
Create a new type. Do not use directly. Use "type MyType".
typeof(x:Any)
Returns type of the given instance
without(arr:Arr, without_elt:Any)
Filter out all occurrences of specific value
~(something:Any, t:Type)
Match a type. Same as "something is t".