Fun type

Function type: native method, user defined method, or a multimethod

Methods

%(x:Any, cb:Fun) Source: stdlib.ngs:609
Each operator. Same as calling x.each(cb)

Example

[1,2,3,4] % echo
*(cb:Fun, n:Int) Source: stdlib.ngs:5906
Call cb n times without any parameters and accumulate the results.

Example

a = Box * 2; a[0] is Box and a[1] is Box and a[0] !== a[1]  # true
+(f:Fun, g:Fun) Source: stdlib.ngs:2416
Compose functions

Returns

Fun f(g(...))

Example

F reject(something, predicate) {
	something.filter(not + predicate)
}
/(x:Any, mapper:Fun) Source: stdlib.ngs:604
Map operator. Same as calling x.map(mapper)

Example

[1,2,3,4] / F(x) x * 10
?(x:Any, predicate:Fun) Source: stdlib.ngs:599
Filter operator. Same as calling x.filter(predicate)

Example

[1,2,3,4] ? F(x) x > 2  # [3,4]
\(x:Any, f:Fun) Source: stdlib.ngs:614
Call operator. Same as calling f(x)

Example

[1,2,3,4] \ echo
acquire(l:Lock, cb:Fun) Source: stdlib.ngs:1186
Call cb with lock l held. Releases the lock after cb returns or throws.

Example

l = Lock()
...
l.acquire(F() {
  modify_global_state_safely(...)
})
cached(cb:Fun) Source: stdlib.ngs:6562
Cache cb results. Runs cb only once. TODO: Support arguments.

Returns

New function which wraps cb.

Example

my_func = cached( { expensive(); calculation(); steps(); result } )
use_result_of(my_func())
...
use_result_of(my_func())
collector(al:ArrLike, body:Fun) Source: stdlib.ngs:754
Defines collector { ... collect(...) ... } behaviour for ArrLike. Very similar to collector for Arr. See collector(Arr,Fun).
collector(a:Arr, body:Fun) Source: stdlib.ngs:1447
Defines collector { ... collect(...) ... } behaviour for arrays

Parameters

aInitial array
bodyThe body after collector keyword and possible initial value, wrapped in a function "collector THIS_CODE" or "collector/my_init THIS_CODE"

Returns

Constructed array

Example

items = collector {
  collect(10)
  for(i;2) collect(i)
  collect(20)
}
echo(items)  # Outputs: [10,0,1,20]

# Or start with few items:
items = collector/[100,200] {
  collect(10)
  for(i;2) collect(i)
  collect(20)
}
echo(items)  # Outputs: [100,200,10,0,1,20]
collector(h:Hash, body:Fun) Source: stdlib.ngs:1461
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 array

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}
collector(n:Int, body:Fun) Source: stdlib.ngs:1472
Defines collector { ... collect(...) ... } behaviour for integers (summarizes collected items).

Parameters

nInitial number
bodyThe body after collector keyword and initial value, wrapped in a function "collector/100 THIS_CODE"

Returns

Constructed array

Example

collector/0 { (1...10).each(collect) }  # 55
collector(s:Str, body:Fun) Source: stdlib.ngs:1483
EXPERIMENTAL! Do not use!
collector(s:Set, body:Fun) Source: autoload/Set.ngs:77
Defines collector { ... collect(...) ... } behaviour for Set.
Diff(a:Arr, b:Arr, eq:Fun)experimental Source: stdlib.ngs:3182
EXPERIMENTAL! Do not use! Compare arrays using eq as equality test. 2*n*m comparisons

Returns

ArrDiff
dir(dirname:Str, cb:Fun, subtype:Any=false, raw:Any=false) Source: stdlib.ngs:4251
List directory contents and call cb with Path() of each found item. Warning: "." and ".." are included.

Returns

unspecified at this time, do not count on it

Example

's=Stats(); dir("tmp/v8", {s.push(A.typeof().name)}, true); s  # <Stats: {File=23, Dir=16}>'
each(mm:MultiMethod, cb:Fun) Source: stdlib.ngs:141
Call cb for each method of the MultiMethod

Example

echo.each(F(method) echo("${method.params().name.join(", ")}"))
each(al:ArrLike, cb:Fun) Source: stdlib.ngs:727
Call cb for each element in the underlying array.
each(hl:HashLike, cb:Fun) Source: stdlib.ngs:805
Iterate over keys and values.

Returns

hl

Example

my_hashlike.each(F(k, v) echo("$k=$v"))
each(r:NumRange, cb:Fun) Source: stdlib.ngs:1344
Iterates over the elements of r, passing each in turn to cb.

Parameters

cbFunction to be called with values from r

Returns

r

Example

s=0
(1...10).each(F(i) { global s; s+=i })
echo(s)  # Outputs: 55
each(arr:Arr, cb:Fun) Source: stdlib.ngs:1746
Iterates over the elements of arr, passing each in turn to cb along with args: cb(ITEM)

Parameters

cbFunction to be called with values from arr

Returns

arr

Example

s=0
[1,2,3].each(F(i) { global s; s+=i })
echo(s)  # Outputs: 6
each(arr:Arr, n:Int, cb:Fun) Source: stdlib.ngs:1807
Process each N elements of an Array at a time. Throws InvalidArgument if number of items in arr is not divisible by n. cb is called as cb(eltI, ..., eltJ) where I is multiple of n and J is I+n-1

Parameters

arrItems to iterate in chunks of n
nNumber of items in chunk
cbFunction to be called with values from arr

Returns

arr

Example

[1,2,3,4].each(2, F(a, b) echo("$a - $b"))  # Outputs: "1 - 2" and on the next line "3 - 4"
each(h:Hash, cb:Fun) Source: stdlib.ngs:2428
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(fb:FullBox, cb:Fun) Source: stdlib.ngs:2862
Call cb with the value of the FullBox

Returns

fb

Example

Box(10).each(echo)  # Output: 10
each(eb:EmptyBox, cb:Fun) Source: stdlib.ngs:2867
Do nothing

Returns

eb

Example

Box(null).each(echo)  # No output
each(s:Success, fun:Fun) Source: stdlib.ngs:3063
Run fun with wrapped value.
each(f:Failure, fun:Fun) Source: stdlib.ngs:3079
No-op, returns f

Returns

f
each(n:Int, cb:Fun) Source: stdlib.ngs:3300
Iterate from zero up to but not including n

Parameters

cbFunction to call with current number

Returns

n

Example

10.each(echo)  # Outputs numbers from 0 to 9 inclusive, one on each line
each(s:Str, cb:Fun) Source: stdlib.ngs:3397
Iterates over all string characters (currently bytes).

Parameters

cbFunction to be called with each character from s

Returns

s

Example

"abc".each(echo)
# Output:
# a
# b
# c
each(rd:ResDef, cb:Fun) Source: autoload/Res.ngs:80
Call cb with properties of each found resource

Returns

rd

Example

AWS::Instance().each(F(i) echo(i.InstanceId))
each(i:Iter, cb:Fun) Source: autoload/Iter.ngs:98
Calls cb with each element from i

Returns

i

Example

Iter(10).each(echo)  # Prints 0 to 9
each(s:Set, cb:Fun) Source: autoload/Set.ngs:30
Call cb for each value in the set

Returns

s
each(t:Table, cb:Fun) Source: autoload/Table.ngs:98
Please do not use. This method might change. Call cb with each table row.
each_chunk(e:Eachable1, n:Int, cb:Fun)experimental Source: stdlib.ngs:2333
Call cb with array of maximum length of n, repeatedely for all items of e. TODO: better doc
each_group_test(tr:TestsResults, cb:Fun) Source: autoload/TestsResults.ngs:56
Undocumented
each_idx_key_val(h:Hash, cb:Fun) Source: stdlib.ngs:2470
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"
each_idx_val(e:Eachable1, cb:Fun) Source: stdlib.ngs:1757
Iterates over elements of e, passing each in turn to cb along with index and args: cb(INDEX, ITEM)

Returns

e

Example

"abc".each_idx_val(F(idx, val) echo("Element #$idx equals to $val"))
each_idx_val(arr:Arr, cb:Fun) Source: stdlib.ngs:1769
Iterates over the elements of arr, passing each in turn to cb along with index and args: cb(INDEX, ITEM)

Returns

arr

Example

[10,20,30].each_idx_val(F(idx, val) echo("Element #$idx equals to $val"))
eachk(h:Hash, cb:Fun) Source: stdlib.ngs:2441
Iterate a Hash.

Parameters

hHash to iterate
cbFunction to call with successive keys

Returns

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

Parameters

hHash to iterate
cbFunction to call with successive values

Returns

h
filter(hl:HashLike, predicate:Fun) Source: stdlib.ngs:828
Filter hash. Build new HashLike with kev-value pairs selected by predicate.

Parameters

predicateTest function to be called with one key and one value at a time.

Returns

HashLike

Example

my_hashlike.filter(F(k, v) k == 'a')
filter(rd:ResDef, predicate:Fun) Source: autoload/Res.ngs:93
Create new resource definition by filtering resources of rd.

Parameters

rdOriginal resource definition. Not modified.

Returns

ResDef

Example

# Get instances with last private IP octet less than 20:
AWS::Instance().filter({A.PrivateIpAddress.split(".")[-1].Int()<20})
filter(i:Iter, predicate:Fun) Source: autoload/Iter.ngs:181
EXPERIMENTAL! Do not use!
finally(body:Fun, cleanup:Fun) Source: stdlib.ngs:1523
Run cleanup after successful execution of body or exception in body

Parameters

bodyMain code to execute
cleanupCleanup code to execute

Returns

Whatever body call returns

Example

finally(
  { while entry = c_readdir(d) { ... } },
  { ... c_closedir(d) ...}
)
# Alternative function call syntax:
finally()
  body => {
    while entry = c_readdir(d) {
      cb(Path(dirname / entry.d_name, subtype=subtype))
    }
  }
  cleanup => {
    r = c_closedir(d)
    r != 0 throws DirFail('Failed to close directory after listing').set('dirname', dirname)
  }
group(e:Eachable1, cb:Fun) Source: stdlib.ngs:2732
Group items from e by key returned by cb

Returns

Hash with Arr values

Example

["ab", "ac", "ba", "bc", "bd"].group(F(x) x[0])  # {a=[ab,ac], b=[ba,bc,bd]}
Hash(arr:Arr, cb:Fun) Source: stdlib.ngs:2650
Create a Hash from keys in arr using cb for values calculation

Parameters

arrKeys 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}
init(t:Thread, name:Str, f:Fun, arg:Any) Source: stdlib.ngs:3831
Creates and runs a thread. The code that the created thread runs is f, which is passed arg.
init(t:Thread, f:Fun, arg:Any) Source: stdlib.ngs:3852
Creates and runs a thread. The code that the created thread runs is f, which is passed arg.
init(t:Thread, f:Fun) Source: stdlib.ngs:3857
Creates and runs a thread. The code that the created thread runs is f without arguments.
init(t:Thread, name:Str, f:Fun) Source: stdlib.ngs:3862
Creates and runs a thread. The code that the created thread runs is f without arguments.
init(i:MapIter, upstream_iter:Iter, mapper:Fun) Source: autoload/Iter.ngs:111
EXPERIMENTAL! Do not use!
init(i:FunIter, f:Fun) Source: autoload/Iter.ngs:193
Undocumented
init(mp:MethodParams, f:Fun) Source: autoload/MethodParams.ngs:7
Undocumented
init(md:MethodDescription, method:Fun)
Undocumented
init(md:MethodDescription, containing_nd:NamespaceDescription, name:Str, mmd:MultiMethodDescription, method:Fun)
Undocumented
init(md:MethodDescription, containing_nd:NamespaceDescription, name:Str, method:Fun)
Undocumented
Iter(f:Fun) Source: autoload/Iter.ngs:190
Undocumented
lines(s:Str, cb:Fun) Source: stdlib.ngs:3594
Split s to strings using end-of-line separators and call cb for each one of the lines. TODO: More efficient implementation, which would not have temporary array of all lines.

Parameters

cbFunction to be called with each line
lines(f:File, cb:Fun) Source: stdlib.ngs:4553
Iterate over lines of the file

Parameters

fClosed File
cbfunction to call with successive lines from the file
lines(p:Process, cb:Fun) Source: stdlib.ngs:5346
Iterate lines of Process' stdout, calling cb with successive lines. Warning: current implementation waits for the process to finish, accumulates all its stdout, and only then starts calling cb for each line.
lines(pp:ProcessesPipeline, cb:Fun) Source: stdlib.ngs:5362
Wait for pp and return call cb for each line of stdout of last process. Warning: current implementation waits for the processes to finish, accumulates all stdout of the last process, and only then starts calling cb for each line.

Returns

Arr of Str
map(e:Eachable, mapper:Fun) Source: stdlib.ngs:279
Map e to an Arr (array) of values using mapper.

Parameters

eObject of any type that has each(e, callback) implemented

Returns

Arr

Example

[1,2,3].map(X*4)  # [4,8,12]
map(arr:Arr, n:Int, mapper:Fun) Source: stdlib.ngs:1828
Map each N elements of an Array at a time. mapper is called as cb(eltI, ..., eltJ) where I is multiple of n and J is I+n-1 Throws InvalidArgument if number of items in arr is not divisible by n. mapper is called as mapper(eltI, ..., eltJ) where I is multiple of n and J is I+n-1

Parameters

arrItems to iterate in chunks of n
nNumber of items in chunk
mapperFunction to be called with values from arr

Returns

Arr

Example

[1,2,3,4].map(2, F(a,b) "$a=$b").join("&")  # Outputs: 1=2&3=4
map(h:Hash, mapper:Fun) Source: stdlib.ngs:2486
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(fb:FullBox, mapper:Fun) Source: stdlib.ngs:2852
Map FullBox value

Parameters

mappermapper to be called with the FullBox value

Returns

FullBox with value returned by mapper

Example

Box(10).map(X*2)  # <FullBox val=20>
map(eb:EmptyBox, mapper:Fun) Source: stdlib.ngs:2857
Do nothing

Returns

eb

Example

EmptyBox().map(X*2)  # <EmptyBox>
map(s:Success, fun:Fun) Source: stdlib.ngs:3070
Run fun with wrapped value. If exception is thrown, Failure is returned; otherwise Success with new vaule is returned.

Returns

Result
map(f:Failure, fun:Fun) Source: stdlib.ngs:3083
No-op, returns f

Returns

f
map(i:Iter, mapper:Fun) Source: autoload/Iter.ngs:122
EXPERIMENTAL! Do not use!
map_base_idx(base:Any, n:Int, mapper:Fun)deprecated Source: stdlib.ngs:581
Deprecated. Map when there is more than one element. If there is exactly one element, it's left as is

Parameters

mapperWill be called with zero based index and successive elements from arr

Returns

Arr
map_idx_key_val(hl:HashLike, mapper:Fun) Source: stdlib.ngs:821
Undocumented
map_idx_key_val(h:Hash, mapper:Fun) Source: stdlib.ngs:2497
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']
map_idx_val(e:Eachable1, mapper:Fun) Source: stdlib.ngs:1779
Map an Eachable1 to an Arr (array) of values using mapper mapper is called as mapper(INDEX, ITEM)

Returns

New Arr

Example

echo("Array items: " + ArrLike().push(10).push(20).push(30).map_idx_val(F(idx, val) "[$idx]=$val").join(", "))
# Outputs: Array items: [0]=10, [1]=20, [2]=30
map_idx_val(arr:Arr, mapper:Fun) Source: stdlib.ngs:1787
Map an Arr to an Arr (array) of values using mapper mapper is called as mapper(INDEX, ITEM)

Returns

New Arr

Example

echo("Array items: " + [10,20,30].map_idx_val(F(idx, val) "[$idx]=$val").join(", "))
# Outputs: Array items: [0]=10, [1]=20, [2]=30
mapk(h:Hash, mapper:Fun) Source: stdlib.ngs:2516
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:2547
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}
mapo(e:Eachable1, mapper:Fun)experimental Source: stdlib.ngs:290
EXPERIMENTAL! Do not use! Map e to same type. Mnemonics: "map original" / "MAP to Original type".

Parameters

eobject of any type that has each(e, callback) implemented Eachable1. WARNING: instances of same type as e must have empty constructor and push() method.

Returns

Of same type as e

Example

Set([1,2]).mapo(X*2)  # Set([2,4])
mapo(s:Str, mapper:Fun) Source: stdlib.ngs:3622
Map a string, character by character.

Returns

Str

Example

"abcd".mapo(F(x) if x == "b" then "X" else x)  # "aXcd"
mapv(h:Hash, mapper:Fun) Source: stdlib.ngs:2535
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}
max(e:Eachable1, cb:Fun)deprecated Source: stdlib.ngs:2208
EXPERIMENTAL! Do not use!
merge_sorted(a:Arr, b:Arr, lte:Fun) Source: stdlib.ngs:2267
Merge sorted arrays.

Parameters

lteLess-then-or-equal function to use for comparison of items in a and b

Returns

Arr

Example

merge_sorted([1,3,10], [0, 7], (<=))  # [0, 1, 3, 7, 10]
min(e:Eachable1, cb:Fun)deprecated Source: stdlib.ngs:2202
EXPERIMENTAL! Do not use!
none(e:Eachable1, predicate:Fun) Source: stdlib.ngs:1718
Check that there is no element in e that satisfies the given predicate. Exactly same as not(any(e, predicate)) .

Returns

Bool

Example

[0,1,2].none(X>2)  # true
[0,1,2].none(X<2)  # false
only(predicate:Any, mapper:Fun) Source: stdlib.ngs:304
Transform mapper to handle only items matching predicate. Non-matching items will be returned as is.

Example

["abc", 1, "def", 2].map(only(Int, X*2))  # ["abc", 2, "def", 4]
opt_prop(rd:ResDef, name:Str, props:Hash, cb:Fun) Source: autoload/Res.ngs:214
Run cb with optional resource property if it exists, uses opt_prop(ResDef, Str, Hash)
partial(f:Fun, *bind_args:Arr) Source: stdlib.ngs:207
Returns partially-applied function

Parameters

fThe base function
partial_tail(f:Fun, *bind_args:Arr) Source: stdlib.ngs:214
Same as partial() but the bound arguments are last ones
pmap(e:Eachable1, mapper:Fun) Source: stdlib.ngs:3901
Parallel map. Runs mapper in threads. Each thread processes one element from the array but this might change in future (preserving the total number of calls to mapper and the order of results).

Returns

Arr, result of applying mapper to elements of e, preserving the order.

Example

pages_texts = abs_pages_urls.pmap(F(url)  `lynx -dump $url`)
Pred(f:Fun) Source: stdlib.ngs:267
Convert a function to predicate.

Returns

The given function, without any transformation
ptimes(n:Int, cb:Fun) Source: stdlib.ngs:3907
Run cb in n parallel threads. Each thread runs one cb but this might change in future (preserving the total n calls to cb).
reduce(something:Eachable1, start:Any, f:Fun) Source: stdlib.ngs:538
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.

Parameters

somethingobject of any type that has each(something, callback) implemented
startFirst argument of f, for the first call of f
fThe combining function

Example

F sum(something) something.reduce(0, (+))
reduce(e:Eachable1, f:Fun) Source: stdlib.ngs:559
Combine items to a single value using the supplied binary function First f is applied to the first two elements of e then on each step f is applied to previous result and next element of e. Throws EmptyEachableFail if e has no elements. If e has only one element, that element is returned.

Parameters

eobject of any type that has each(e, callback) implemented
fThe combining function

Example

F sum(e) e.reduce((+))
reject(i:Iter, predicate:Fun) Source: autoload/Iter.ngs:183
EXPERIMENTAL! Do not use!
replace(s:Str, r:RegExp, mapper:Fun) Source: stdlib.ngs:5892
Replace all occurrences of r

Parameters

mapperFunction that will be called with one matching string at a time that provides the replacement

Returns

Str

Example

"x10ab20c30y".replace(/[0-9]+/, F(match_text) "[$match_text]")  # "x[10]ab[20]c[30]y"
Result(fun:Fun) Source: stdlib.ngs:3028
Runs the computation and wraps the result: a value is wrapped in Success and an exception is wrapped in Failure.

Returns

Success or Failure
retry(times:Int=60, sleep:Any=1, logger:Fun=method, success_predicate:Any=method, title:Any='<retry>', progress_cb:Fun=method, success_cb:Fun=method, fail_cb:Any=method, body:Fun=method) Source: stdlib.ngs:6357
Retry. Executes given "body" "times" times. Throws RetryFail if all calls fail and fail_cb is not provided.

Parameters

timesLimit of times to run "body"
sleepEither sleep in seconds between tries or Iter that returns successive sleep times in seconds
loggerFunction to use to log attempts, caught body exceptions and sleep times. Defaults to stdlib's debug.
success_predicateCANDIDATE FOR REMOVAL. Run against body results to. Says whether the attempt succeeded. Defaults to Bool.
titlePrefix strings sent to logger with this string. Defaults to "<retry>".
progress_cbCalled before each attempt with (1) current attempt number and (2) limit of attempts ("times"). Defaults to do nothing.
success_cbCalled when body succeeds with the result that comes from body. Defaults to identity function.
fail_cbIf passed, called if all attempts fail. Defaults to null.

Returns

Any. Result of success_cb or result of fail_cb.

Example

page = retry(times=10, sleep=ExpBackIter(), body={ try `curl "http://flaky-site.com"` })
sort(a:Arr, lte:Fun=method) Source: stdlib.ngs:2291
Sort an array.

Parameters

lteLess-then-or-equal function to use for comparison of the items in a

Returns

Arr

Example

sort([0,5,3,-1], (<=))  # [-1, 0, 3, 5]
sort(a:Arr, field:Str, lte:Fun=method) Source: stdlib.ngs:2304
Sort an array based on field value

Parameters

lteLess-then-or-equal function to use for comparison of the items' fields

Returns

Arr

Example

[{'x': 1}, {'x': 5}, {'x': 3}].sort('x')  # [{'x': 1}, {'x': 3}, {'x': 5}]
sort(h:Hash, lte:Fun=method) Source: stdlib.ngs:2767
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:2616
Sort Hash by keys

Returns

Hash

Example

{'b': 2, 'c': 11, 'a': 1}.sortk()  # {'a': 1, 'b': 2, 'c': 11}
StrParams(f:Fun) Source: stdlib.ngs:901
Do not use!
tap(val:Any, cb:Fun) Source: stdlib.ngs:590
Call cb with val

Returns

val

Example

long_computation_part1().tap(F(x) echo("DEBUG: $x")).long_computation_part2()
test(name:Str, f:Fun) Source: autoload/test.ngs:18
Runs f as a test.

Parameters

nameHuman readable name of the test.
fA Fun that will either throw TestFail, return TestMessage. Other values are ignored by the testing framework.
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
the_one(e:Eachable1, predicate:Any, body:Fun, found_more:Fun=method, found_none:Fun=method) Source: stdlib.ngs:430
Find the only element that satisfies the predicate and execute given code with the value

Parameters

bodyThe code to execute when exactly one element that satisfies the predicate was found. Executed with the found value. It's value will be returned as result of the_one().
found_moreThe code to execute when more than one element satisfies the predicate. It's value will be returned as result of the_one(). Defaults to function returning null.
found_noneThe code to execute when none of the elements satisfy the predicate. It's value will be returned as result of the_one(). Defaults to function returning null.

Returns

Result of running on of the following: body, found_more, found_none

Example

F name(dn:MethodDocNode) {
	dn.children.the_one(MethodNameDocNode).text[0]
}
time(cb:Fun) Source: stdlib.ngs:6257
Mesure running time of cb in microseconds

Returns

Int
times(n:Int, cb:Fun) Source: stdlib.ngs:3312
Call cb n times without arguments.

Parameters

cbFunction to call

Example

r=0; 5.times(F() r=r+2);  # r is now 10
AWS::regions(cb:Fun) Source: autoload/AWS.ngs:94
Call cb in parallel threads, each with AWS region name as argument.

Parameters

cbMust return an array. regions() sets .Region in the result and flattens the results

Returns

Arr

Example

ins = AWS::regions({ ``aws ec2 describe-instances --region $A $*filters`` })
AWS2::regions(cb:Fun) Source: autoload/AWS2.ngs:94
Call cb in parallel threads, each with AWS region name as argument.

Parameters

cbMust return an array. regions() sets ._Region in the result and flattens the results

Returns

Arr

Example

ins = AWS::regions({ ``aws ec2 describe-instances --region $A $*filters`` })
Doc::each_child(p:Doc::Part, cb:Fun) Source: autoload/Doc.ngs:82
Undocumented
Doc::map_children(p:Doc::Part, mapper:Fun) Source: autoload/Doc.ngs:83
Undocumented
Doc::Transformer(x:Fun) Source: autoload/Doc.ngs:87
Undocumented
Doc::visit(p:Doc::Part, cb:Fun, parents:Arr=[]) Source: autoload/Doc.ngs:111
Undocumented