Types
Function type: an Array of Closures, a Closure, or a native method
Methods
%(x:Any, cb:Fun)
Each operator.
Same as calling x.each(cb)
*(cb:Fun, n:Int)
Call cb n times without any parameters and accumulate the results.
/(x:Any, mapper:Fun)
Map operator.
Same as calling x.map(mapper)
?(x:Any, predicate:Fun)
Filter operator.
Same as calling x.filter(predicate)
\(x:Any, f:Fun)
Call operator.
Same as calling f(x)
collector(a:Arr, body:Fun)
Defines collector { ... collect(...) ... } behaviour for arrays
collector(h:Hash, body:Fun)
Defines collector { ... collect(...) ... } behaviour for hashes
collector(n:Int, body:Fun)
Defines collector { ... collect(...) ... } behaviour for integers (summarizes collected items).
dir(dirname:Str, cb:Fun, subtype:Any=false)
List directory contents and call cb with Path() of each found item. Warning: "." and ".." are included.
each(al:ArrLike, cb:Fun)
Call cb for each element in the underlying array.
each(r:NumRange, cb:Fun)
Iterates over the elements of r, passing each in turn to cb.
each(arr:Arr, cb:Fun)
Iterates over the elements of arr, passing each in turn to cb along with args: cb(ITEM)
each(arr:Arr, n:Int, cb:Fun)
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
each(n:Int, cb:Fun)
Iterate from zero up to but not including n
each(s:Str, cb:Fun)
Iterates over all string characters (currently bytes).
TODO: example.
each_idx_val(arr:Arr, cb:Fun)
Iterates over the elements of arr, passing each in turn to cb along with index and args: cb(INDEX, ITEM)
finally(body:Fun, cleanup:Fun)
TODO: make sure cleanup() is not run twice in case of exception in cleanup() itself
group(a:Arr, cb:Fun)
TODO.
Group items from a by key returned by cb
Hash(arr:Arr, cb:Fun)
Create a Hash from keys in arr using cb for values calculation
lines(s:Str, cb:Fun)
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.
lines(p:Process, cb:Fun)
Iterate lines of Process' stdout, calling cb with successive lines.
Warning: current implementation waits for the process to finish and accumulates all its stdout.
map(something:Eachable, mapper:Fun)
Map something to an Arr (array) of values using mapper.
map(arr:Arr, n:Int, mapper:Fun)
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
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
map_idx_val(arr:Arr, mapper:Fun)
Map an Arr to an Arr (array) of values using mapper
mapper is called as mapper(INDEX, ITEM)
mapk(h:Hash, mapper:Fun)
Map Hash keys. Build new Hash with same values as in h but keys mapped by mapper.
mapkv(h:Hash, mapper:Fun)
Map Hash keys and values. Build new Hash with keys and values mapped by mapper.
mapv(h:Hash, mapper:Fun)
Map Hash values. Build new Hash with same keys as in h but values mapped by mapper.
none(e:Eachable1, predicate:Fun)
Check that there is no element in e that satisfies the given predicate. Exactly same as not(any(e, predicate)) .
only(predicate:Any, mapper:Fun)
Transform mapper to handle only items matching predicate. Non-matching items will be returned as is.
opt_prop(rd:ResDef, name:Str, props:Hash, cb:Fun)
Run cb with optional resource property if it exists, uses opt_prop(ResDef, Str, Hash)
partial(f:Fun, *bind_args:Arr)
Returns partially-applied function
partial_tail(f:Fun, *bind_args:Arr)
Same as partial() but the bound arguments are last ones
Pred(f:Fun)
Convert a function to predicate.
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.
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.
sort(a:Arr, attr:Str, lte:Fun=(a function))
Sort an array based on attribute value
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
times(n:Int, cb:Fun)
Call cb n times without arguments.