Axon Function Ext. Core Flashcards
abs
Return absolute value of a number, if null return null
abs(val)
add
Add item to the end of a list and return a new list.
add(val, item)
addAll
Add all the items to the end of a list and return a new list.
addAll (val, items)
addCol
Add a column to a grid by mapping each row to a new call value. The col parameter may be a simple string name or may be a distionary which must have a “name” tag (any other tags become column meta-data). The mapping funtion takes (row) and returns the new cell values for the column.
addCol (grid, col, fn)
addColMeta
Return a new grid with additional column meta-data
addColMeta (grid, name, meta)
addMeta
Add grid level meta-data tags.
addMeta(grid, meta)
addRow
Add an additional Dict row to the end of a grid.
addRow (grid, newRow)
addRows
Add an list of rows to the end of a grid. The newRows may be expressed as list of Dict or a Grid.
addRows (grid, newRows)
all
Return if all the items in a list, dict, or grid match the given test function. If the collection is empty, then return true.
If working with a list, the function takes (val) or (val, index) and returns true or false.
If working with a dict, theu function takes (val) or (val, name) and returns true or false.
If working with a grid, the function take (row) or (row, index) and returns true or false.
[1, 3, 5] . all v => v.isOdd >> true
[1, 3, 6] .all(isOdd) >>false
any
any(val, fn)
Return if any the items in a list, dict, or grid match the given test function. If the collection is empty, then return false.
If working with a list, the function takes (val)
or (val, index)
and returns true or false.
If working with a dict, the function takes (val)
or (val, name)
and returns true or false.
If working with a grid, the function takes (row)
or (row, index)
and returns true or false.
Examples:
[1, 3, 5].any v =\> v.isOdd \>\> true [2, 4, 6].any(isOdd) \>\> false
as
as(val, unit)
Set the unit of a number. Unlike to no conversion of the scalar of the number is performed. The target unit can be a unit string or a number in which case the scalar value of the unit parameter is ignored (by convention should be 1).
avg
avg(val, acc)
Fold multiple values into their standard average or arithmetic mean. This function is the same as math::mean
. Null values are ignored. Return null if no values.
capitalize
capitalize(val)
Return this string with the first character converted to uppercase. The case conversion is for ASCII only.
chart
chart(val)
Set the grid visualization view to chart.
checkSyntax
checkSyntax(src)
Given an axon expression, validate the syntax. If there are no errors then return an empty grid. If there are errors then return a grid with the “err” tag and a “line” and “dis” column for each error found.
col
col(grid, name, checked: true)
Get a column by its name. If not resolved then return null or throw UnknownNameErr based on checked flag.
colNames
colNames(grid)
Get the column names a list of strings.
colToList
colToList(grid, col)
Get a column as a list of the cell values ordered by row.
cols
cols(grid)
Get the columns from a grid as a list.
colsToLocale
colsToLocale(grid)
Map each col display string to its localized tag name if the col does not already have a display string. Also see Grid.colsToLocale and Localization.
commit
commit(diffs)
Commit a diff
or list of diffs to the folio database.
If one diff is passed, return the new record. If a list of diffs is passed return a list of new records.
Examples:
// add new record newRec: commit(diff(null, {dis:"New Rec!"}, {add})) // add someTag to some group of records readAll(filter).toRecList.map(r =\> diff(r, {someTag})).commit
Side effects:
- writes to folio database
- clears context read cache
concat
concat(list, sep: "")
Concatenate a list of items into a string.
Examples:
[1, 2, 3].concat \>\> "123" [1, 2, 3].concat(",") \>\> "1,2,3"
contains
contains(val, x)
Return if val
contains x
:
- if
val
is Str, thenx
is substring. - if
val
is List, thenx
is item to search. - if
val
is Range, then isx
inside the range inclusively - if
val
is DateSpan, then isx
a date in the span
context
context()
Get the current context as a Dict with the following tags:
-
username
for current user -
userRef
if user maps to a rec in current project -
projName
if evaluating in context of a project -
ruleRef
if evaluating in context of a spark engine rule -
locale
current locale
coord
coord(lat, lng)
Construct a Coord from two Numbers in decimal degrees
coordDist
coordDist(c1, c2)
Given a two Coords, compute the great-circle distance between them in meters using the haversine forumula.
coordLat
coordLat(coord)
Latitude of a Coord as a Number
coordLng
coordLng(coord)
Longitude of a Coord as a Number
count
count(val, acc)
Fold multiple values into their total count Return zero if no values.
curFunc
curFunc()
Get the current top-level function’s tags.
date
date(val, month: null, day: null)
If val is a DateTime: get date portion of the timestamp. If val is a Number: construct a date instance from year, month, day
Examples:
now().date // same as today() date(2010, 12, 1) // same as 2010-12-01
dateTime
dateTime(d, t, tz: null)
Construct a DateTime from a date, time, and timezone name. If timezone is null, use system default.
day
day(d)
Get day of month as integer between 1 to 31 from date or datetime.
debugType
debugType(val)
Return a string of the given value’s type. No guarantee is made for the string’s format. Applications must not assume any specific format, this function if for human consumption only.
decapitalize
decapitalize(val)
Return this string with the first character converted to lowercase. The case conversion is for ASCII only.
diff
diff(orig, changes, flags: null)
Construct a modification “diff” used by commit
. The orig should be the instance which was read from the project, or it may be null only if the add flag is passed. Any tags to add/set/remove should be included in the changes dict.
The following flags are supported:
-
add
: indicates diff is adding new record -
remove
: indicates diff is removing record (in general you should addtrash
tag instead of removing) -
transient
: indicate that this diff should not be flushed to persistent storage (it may or may not be persisted). -
force
: indicating that changes should be applied regardless of other concurrent changes which may be been applied after the orig version was read (use with caution!)
Examples:
// create new record diff(null, {dis:"New Rec", someMarker}, {add}) // create new record with explicit id like Diff.makeAdd diff(null, {id:151bd3c5-6ce3cb21, dis:"New Rec"}, {add}) // set/add dis tag and remove oldTag diff(orig, {dis:"New Dis", -oldTag}) // set/add val tag transiently diff(orig, {val:123}, {transient})
dis
dis(dict, name: null, def: "")
Get display string for dict or the given tag. If name
is null, then return display text for the entire dict using Etc.dictToDis
. If name
is non-null then format the tag value using its appropiate toLocale
method. Also see Dict.dis
.
dst
dst(dt)
Given a DateTime in a specific timezone, return true if the time is in daylight savings time or false if standard time.
each
each(val, fn)
Iterate the items of a collection:
- Grid: iterate the rows as (row, index)
- List: iterate the items as (value, index)
- Dict: iterate the name/value pairs (value, name)
- Range: iterate the integer range (integer)
eachDay
eachDay(dates, f)
Iterate the days for where dates
may be any object converted into a date range bytoDateSpan
. The given function is called with a Date
argument for each iterated day.
Example:
f: day =\> echo(day) eachDay(2010-07-01..2010-07-03, f) \>\> iterate Jul 1st, 2nd, 3rd eachDay(2010-07, f) \>\> iterate each day of July 2010 eachDay(pastWeek, f) \>\> iterate last 7 days
eachMonth
eachMonth(dates, f)
Iterate the months for where dates
may be any object converted into a date range bytoDateSpan
. The given function is called with a DateSpan
argument for each interated month.
Examples:
// iterate each month in 2010, and echo data range eachMonth(2010) d =\> echo(d) // call f once for current method eachMonth(today(), f)
<dl>
</dl>
eachWhile
eachWhile(val, fn)
Iterate the items of a collection until the given function returns non-null, then break the iteration and return the resulting object. Return null if the function returns null for every item.
- Grid: iterate the rows as (row, index)
- List: iterate the items as (value, index)
- Dict: iterate the name/value pairs (value, name)
- Range: iterate the integer range (integer)
echo
echo(x)
Write the string represenation of x
to standard out. Return x as result.
Side effects:
- performs I/O to stdout
end
end(val)
End value of a DateSpan, DateTimeSpan, or a range.
endsWith
endsWith(val, sub)
Return if Str ends with the specified Str.
eval
eval(expr)
Evaluate the given expression formatted as a string.
exts
exts(opts: null)
List the extensions available for the system. Return grid with following columns:
- name: programatic unique name for extension
- dis: display name of extension (based on opts->locale)
- extStatus: ok, disabled, unlicenced, licFault, warn
- extStatusMsg: description of status error
- enabled: marker tag for extensions currently enabled on cur project
- id: record id if enabled
- app: qualified type of Fantom app if extension publishes a UI app
- settings: qualified type of Fantom pane if extension publishes a settings UI
- admin: marker if app requires admin permissions
- icon24: uri to 24x24 icon
- icon72: uri to 72x72 icon
- iconTable: uri to 16x16 icon to use in tabular displays
- depends: list of extension names separated by comma
The options parameter supports following tags:
- locale: language locale formatted as Locale.toStr
filterToFunc
filterToFunc(filterExpr)
Convert a filter expression to a function which may be used with findAll
or find
. The returned function accepts one parameter of Dicts and returns true/false if the Dict is matched by the filter. Also see parseFilter
.
Examples:
// filter for dicts with 'equip' tag list.findAll(filterToFunc(equip)) // filter rows with an 'area' tag over 10,000 grid.findAll(filterToFunc(area \> 10\_000))
find
find(val, fn)
Find the first matching item in a list or grid by applying the given filter function. If no match is found return null.
If working with a list, the filter should be a function that takes (val)
or (val, index)
. It should return true to match and return the item.
If working with a dict, the filter should be a function that takes (val)
or (val, name)
. It should return true to match and return the item.
If working with a grid, the filter function takes (row)
or (row, index)
and returns true to match and return the row.
findAll
findAll(val, fn)
Find all the items in a list, dict, or grid by applying the given filter function. Also see find
.
If working with a list, the filter should be a function that takes (val)
or (val, index)
. It should return true to keep the item.
If working with a dict, the filter should be a function that takes (val)
or (val, name)
. It should return the true to keep the name/value pair.
If working with a grid, the filter function takes (row)
or (row, index)
and returns true to keep the row. The resulting grid shares the original’s grid meta and columns.
first
first(val)
Get the first item from an ordered collection or return null if the collection is empty:
- list: item at index 0
- grid: first frow
fold
fold(list, fn)
Fold a list into a single value using a folding function with the signature of (val, acc)
where val is the items being folded, and acc is an accumulator used to maintain state between interations. Lifecycle of a fold:
- Call
fn(foldStart, null)
, return initial accumulator state - Call
fn(item, acc)
for every item, return new accumulator state - Call
fn(foldEnd, acc)
return final result
The fold will short-circuit and halt immediately if the folding function returns na
for the accumulator state. The result of the fold is na
in this case. A folding function should document its behavior when a collection contains na
.
Example:
[1, 2, 3, 4].fold(max) // fold list into its max value [1, 2, 3, 4].fold(avg) // fold list into its average value [1, 2, na(), 3].fold(sum) // =\> na()
Example of writing your own custom fold function that used start/end values and has support for na():
average: (val, acc) =\> do if (val == foldStart()) return {sum:0, count:0} if (val == foldEnd()) return acc-\>sum / acc-\>count if (val == na()) return na() return {sum: acc-\>sum + val, count: acc-\>count + 1} end
foldCol
foldCol(grid, colName, fn)
Fold the values of the given column into a single value using a folding function using same semantics as fold
.
foldCols
foldCols(grid, colSelector, newColName, fn)
Fold a set of columns in each row into a new folded column and return a new grid. The columns to fold are selected by the colSelector
function and removed from the result. The selector may be a list of string names or a function which takes a Col and returns true to select it. The folding function uses same semantics as fold
.
Example:
// consider grid 'g' with the following structure: a b c --- --- --- 1 10 100 2 20 200 // foldCols, add b and c together to create new bc column g.foldCols(["b", "c"], "bc", sum) // yields this grid: a bc --- --- 1 110 2 220 // we could also replace list of col names with a function colSel: col =\> col.name == "b" or col.name == "c" g.foldCols(colSel, "bc", sum)
foldEnd
foldEnd()
The fold end marker value TODO: this API is subject to change
foldStart
foldStart()
The fold start marker value TODO: this API is subject to changefoldStart()
The fold start marker value TODO: this API is subject to change
folioCompact
folioCompact()
Asynchronously kick off a database compaction operation for current project. Requires super user permission. See Proj.compact
. To run a compaction in a background job usejobFolioCompact
.
folioEmptyTrash
folioEmptyTrash()
Delete all the records marked with trash
tag. See Proj.emptyTrash
folioRestore
folioRestore(ts, opts: null)
Restore snapshot identified by given timestamp Requires super user permission. SeeProj.restore
folioSetMode
folioSetMode(mode)
Set folio database mode: “ro”, “rw”, “disabled” Requires super user permission. SeeProj.mode
folioSnapshot
folioSnapshot()
Asynchronously kick off a new snapshot for current project. Requires super user permission. See Proj.snapshot
To run a snapshot a background job use jobFolioSnapshot
.
folioSnapshotDelete
folioSnapshotDelete(ts)
Delete a snapshot file by its timestamp. Return true if snapshot found and deleted of false otherwise. Requires super user permission.
folioSnapshots
folioSnapshots()
List all the snapshots for the current project:
- ts: timestamp of snapshot
- size: size in bytes of snapshot
format
format(val, pattern: "")
Format an object using the current locale and specified format pattern. Formatting patterns follow Fantom toLocale conventions:
Bool.toLocale
Int.toLocale
Float.toLocale
Duration.toLocale
Date.toLocale
Time.toLocale
DateTime.toLocale
fromJavaMillis
fromJavaMillis(millis, tz: null)
Given Number of milliseconds since Unix epoch of 1-Jan-1970 UTC, return a DateTime in given timezone. If timezone is null, use system default. Also see toJavaMillis
.
func
func(name, checked: true)
Find a top-level function by name and return its tags. If not found throw exception or return null based on checked flag.
funcs
funcs(filterExpr: null)
Find all the top-levels functions in the current project which match the given filter. If the filter is omitted then return all the functions declared in the current project. The function tags are returned. This function automatically removes tags which would be expensive to send over the network like doc
and src
. An override
column is added to indicate if the function if a rec function which overrides a core/extension function.
Examples:
funcs() // all functions funcs(ext == "hvac") // match filter
get
get(val, key)
Get an item from a collection:
- str(num): get character at index as int (same semanatics as Fantom)
- str(range): get string slice (same semanatics as Fantom)
- list(num): get item at given index (same semanatics as Fantom)
- list(range): get list slice at given index (same semanatics as Fantom)
- dict(key): get item with given key or return null
- grid(num): get row at given index
- grid(range):
Grid.getRange
The get function maybe be accessed using the []
shortcut operator:
list[3] \>\> list.get(3)
getSafe
getSafe(val, key)
Get an item from a str, list, or grid safely when an index is out of bounds:
- str(num): get a character at index or null if index invalid
- str(range): get safe slice or “” if entire range invalid
- list(num): get item at given index or null is index invalid
- list(range): get list slice with safe index
- grid(num): get row at given index or null if index invalid
- grid(range):
Grid.getRange
with safe range
gridColKinds
gridColKinds(grid)
Given a grid return the types used in each column as a grid with the following:
-
name
: string name of the column -
kind
: all the different value kinds in the column separated by “|” -
count
: total number of rows with column with a non-null value Also seereadAllTagNames
.
gridColsToDict
gridColsToDict(grid, colToKey, colToVal)
Convert a grid into a dict of name/val pairs which are derived from each column using the given functions. The functions take (col, index)
gridFormats
gridFormats()
Return grid formats installed. See GridFormat
gridRowsToDict
gridRowsToDict(grid, rowToKey, rowToVal)
Convert a grid into a dict of name/val pairs which are derived from each row using the given functions. The functions take (row, index)
has
has(val, name)
If val is a Grid return if it has the given column name. If val is a Dict return if the given name is mapped to a non-null value
heading
heading(text)
Construct heading view
hour
hour(t)
Get hour of day as integer between 0 to 23 from time or datetime
hoursInDay
hoursInDay(dt)
Given a DateTime in a specific timezone, return the number of hours in the day. Dates which transition to DST will be 23 hours and days which transition back to standard time will be 25 hours.
index
index(val, x, offset: 0)
Return the first match of x
in val
searching forward, starting at the specified offset index. A negative offset may be used to access from the end of string. Return null if no occurences are found:
- if
val
is Str, thenx
is substring. - if
val
is List, thenx
is item to search.
indexr
indexr(val, x, offset: Number.negOne)
Return the last match of x
in val
searching backward, starting at the specified offset index. A negative offset may be used to access from the end of string. Return null if no occurences are found:
- if
val
is Str, thenx
is substring. - if
val
is List, thenx
is item to search.
insert
insert(val, index, item)
Insert an item into a list at the given index and return a new list.
insertAll
insertAll(val, index, items)
Insert a list of items at the given index and return a new list.
invoke
invoke(rec, action, args: {})
Invoke an action on the given rec (any value supported by toRec
). The record must have a valid actions
grid configured with a dis string matching the the action
parameter. SeeActions.
isAlpha
isAlpha(num)
Is number an ASCII alpha char: isUpper||isLower
isAlphaNum
isAlphaNum(num)
Is number an ASCII alpha-numeric char: isAlpha||isDigit
isBool
isBool(val)
Return if an object is a boolean type
isDate
isDate(val)
Return if an object is a Date type
isDateTime
isDateTime(val)
Return if an object is a DateTime type
isDict
isDict(val)
Return if an object is a dict type
isDigit
isDigit(num, radix: 10)
Is number a digit in the specified radix. A decimal radix of ten returns true for 0-9. A radix of 16 also returns true for a-f and A-F.
isEmpty
isEmpty(val)
Return if a collection is empty: str, list, dict, or grid
isEven
isEven(val)
Return if an integer is an even number.
isFunc
isFunc(val)
Return if an object is a function type
isGrid
isGrid(val)
Return if an object is a grid type
isKeyword
isKeyword(val)
Return if given string is an Axon keyword
isList
isList(val)
Return if an object is a list type
isLower
isLower(num)
Is number an ASCII lowercase alphabetic char: a-z
isMetric
isMetric(val: null)
Given an optional value return true if the SI metric system should be used or false if the United States customary unit system should be used. The following rules are used:
- if val is a dict with
geoCountry
return return false if “US” - if number or rec with
unit
and unit is known to be a US customary unit return false (right now we only check for °F and Δ°F) - fallback to locale of hosting server, see
Locale
Examples:
isMetric({geoCountry:"US"}) \>\> false isMetric({geoCountry:"FR"}) \>\> true isMetric(75°F) \>\> false isMetric({unit:"Δ°C"}) \>\> true isMetric() \>\> fallback to server locale
isNaN
isNaN(val)
Return if val
is the Number representation of not-a-number
isNumber
isNumber(val)
Return if an object is a number type
isOdd
isOdd(val)
Return if an integer is an odd number.
isRef
isRef(val)
Return if an object is a ref type
isSpace
isSpace(num)
Is number is whitespace char: space \t \n \r \f