Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Compare this object to the specified for equality. This
method may be accessed via the == and != shortcut operators.
If not overridden the default implementation compares for
reference equality using the === operator. If this method
is overridden, then hash() must also be overridden such that
any two objects which return true for equals() must return
the same value for hash(). This method must accept null
and
return false.
Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return a string representation of this object.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
_Set the unit of a number. Unlike to() function, 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).
Examples:
75°F.as(1°C)
75°F.as("°C")
Static
_Static
_Return if two values are equivalent. Unlike the standard ==
operator this function will compare the contents of
collection values such as lists, dicts, and grids. For
non-collection values, the result is the same as the ==
operator. This function does not work with lazy grids such
as hisRead result.
Static
_Static
_Function for the ->
operator. If the given value is a dict,
then get a value by name, or throw UnknownNameErr if name
not mapped. If the value is a Ref, then perform a checked readById
,
then perform the name lookup.
The trap function maybe be accessed using the ->
shortcut
operator:
dict->foo >>> dict.trap("foo")
Static
absStatic
addStatic
addStatic
addAdd a column to a grid by mapping each row to a new cell
value. The col
parameter may be a simple String name or may
be a dictionary which must have a "name" tag (any other tags
become column meta-data). The mapping function takes (row)
and returns the new cell values for the column.
Examples:
// add new column named areaMeter
readAll(site).addCol("areaMeters") s => s->area.to(1m²)
// add new column named areaMeter with dis meta
readAll(site).addCol({name:"areaMeters", dis:"Area Meters"}) s => s->area.to(1m²)
Static
addReturn a new grid with additional column meta-data. If column not found, then return given grid. Column meta is added using merge conventions. Also see setColMeta and docHaxall::Streams#addColMeta.
Static
addAdd grid b as a new set of columns to grid a. If b contains duplicate column names, then they are given auto-generated unique names. If b contains fewer rows then a, then the missing cells are filled with null.
Examples:
[{a:0, b:2}, {a:1, b:3}].toGrid.addCols({c:4}.toGrid)
readAll(rtu).addCols(readAll(meter))
Static
addStatic
addStatic
addStatic
allReturn 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, 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.
If working with a string, the function takes (char)
or (char, index)
and returns true or false.
If working with a stream, then function takes (val)
and
returns true or false. See docHaxall::Streams#all.
Examples:
[1, 3, 5].all v => v.isOdd >> true
[1, 3, 6].all(isOdd) >> false
Static
anyReturn 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.
If working with a string, the function takes (char)
or (char, index)
and returns true or false.
If working with a stream, then function takes (val)
and
returns true or false. See docHaxall::Streams#any.
Examples:
[1, 3, 5].any v => v.isOdd >> true
[2, 4, 6].any(isOdd) >> false
Static
avgFold 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.
Example:
[7, 2, 3].fold(avg) >> 4
Static
callReflectively call a function with the given arguments. The func may be a Str name or an expression that evaluates to a function. Args is a positional list for each argument. Examples:
call("today")
call("replace", ["hi there", "hi", "hello"])
call("parseDate", ["2021-03-15"])
call("parseDate", ["15-Mar-21", "DD-MMM-YY"])
call(parseDate, ["15-Mar-21", "DD-MMM-YY"])
call(parseDate(_, "DD-MMM-YY"), ["15-Mar-21"])
Static
capitalizeReturn this string with the first character converted to uppercase. The case conversion is for ASCII only. Also see decapitalize() and upper().
Examples:
capitalize("apple") >> "Apple"
Static
clampClamp the number val between the min and max. If its less than min then return min, if its greater than max return max, otherwise return val itself. The min and max must have matching units or be unitless. The result is always in the same unit as val.
Examples:
14.clamp(10, 20) >> 14 // is between 10 and 20
3.clamp(10, 20) >> 10 // clamps to min 10
73.clamp(10, 20) >> 20 // clamps to max 20
45°F.clamp(60, 80) >> 60°F // min/max can be unitless
Static
colStatic
collectCollect stream into a in-memory list or grid. See docHaxall::Streams#collect.
Static
colStatic
colsStatic
colsLocalize column display names. For each col which does not
have an explicit dislay name, add a dis
tag based on the
column name. Also see haystack::Grid.colsToLocale
and docSkySpark::Localization#tags.
Static
colGet a column as a list of the cell values ordered by row. Also see rowToList().
Example:
readAll(site).colToList("dis")
Static
compStatic
concatConcatenate a list of items into a string.
Examples:
[1, 2, 3].concat >> "123"
[1, 2, 3].concat(",") >> "1,2,3"
Optional
sep: stringStatic
conjunctsStatic
containsStatic
coordStatic
coordStatic
coordStatic
coordStatic
countStatic
curGet the current top-level function's tags.
Static
dateStatic
dateStatic
dayStatic
dayStatic
debugReturn 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 is for human consumption only.
Static
decapitalizeReturn this string with the first character converted to lowercase. The case conversion is for ASCII only. Also see capitalize() and lower().
Examples:
decapitalize("Apple") >> "apple"
Static
defStatic
defsStatic
disGet display string for dict or the given tag. If name
is
null, then return display text for the entire dict using haystack::Etc.dictToDis.
If name
is non-null then format the tag value using its
appropiate toLocale
method. Also see haystack::Dict.dis.
Optional
name: stringOptional
def: stringStatic
dstReturn if a DateTime is in daylight saving time. For the given DateTime and its specific timezone, return true if the time is in daylight savings time or false if standard time.
Static
eachIterate the items of a collection:
Static
eachIterate the days of a span. The dates
argument may be any
object converted into a date range by toDateSpan.
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
Static
eachIterate the months of a span. The dates
argument may be any
object converted into a date range by toDateSpan.
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)
Static
eachIterate the items of a collection until the given function returns non-null. Once non-null is returned, then break the iteration and return the resulting object. Return null if the function returns null for every item.
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
endStatic
endsReturn if Str ends with the specified Str.
Examples:
"hi there".endsWith("there") >> true
"hi there".endsWith("hi") >> false
Static
evalEvaluate an Axon string expression. The evaluation happens in a new scope and does not have access to the current scope of local variables. Also see call() and toAxonCode().
Examples:
eval("2 + 2")
eval("now()")
Static
evalEvalate an Axon string expression to a function. Typically the expression is just a function name, but it can be any expression that evaluates to a function. Raise an exception if the expression does not evaluate to a function. Note this call does evalute the given expression in the runtime, so it must be used with caution - never use it with a string from a non-trusted origin.
Examples:
evalToFunc("now").call
evalToFunc("(x, y)=>x+y").call([3, 4])
(evalToFunc("(x, y)=>x+y"))(3, 4)
evalToFunc("""replace(_, "x", "_")""").call(["xyz"])
Static
filterApply a filter expression to a collection of dicts. The collection value may be any of the following:
The filter parameter may one fo the following:
Examples:
// apply to a list of dicts
[{v:1}, {v:2}, {v:3}, {v:4}].filter(v >= 3)
// apply to a grid and return new grid with matching rows
readAll(equip).filter(meter)
// apply to a list of columns
read(ahu).toPoints.hisRead(yesterday).cols.filter(kind=="Bool")
// apply to a stream of dicts
readAllStream(equip).filter(siteMeter and elec and meter).collect
// apply search filter
readAll(equip).filter(parseSearch("RTU-1"))
Static
filterConvert a filter expression to a function which maybe used with findAll or find. The returned function accepts one Dict parameter and returns true/false if the Dict is matched by the filter. Also see filter() and 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))
Static
findFind 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.
If working with a stream, the filter takes (val)
and returns
true to match. See docHaxall::Streams#find.
Examples:
// find first string longer than 3 chars
["ape", "bat", "charlie", "dingo"].find(x => x.size > 3)
// find first odd number
[10, 4, 3, 7].find(isOdd)
Static
findFind 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.
If working with a stream, the filter takes (val)
and returns
true to match. See docHaxall::Streams#findAll.
Examples:
// find all the strings longer than 3 chars
["ape", "bat", "charlie", "dingo"].findAll(x => x.size > 3)
// find even numbers
[0, 1, 2, 3, 4].findAll(isEven)
// find all the sites greater than 10,000ft from grid
readAll(site).findAll(s => s->area > 10_000ft²)
Static
firstGet the first item from an ordered collection or return null if the collection is empty:
Static
firstGet the first day of given date's month. Also see lastOfMonth().
Example:
2009-10-28.firstOfMonth >> 2009-10-01
Static
flatMap each item in a list or grid to zero or more new items as a flattened result.
If mapping a list, the mapping should be a function that
takes (val)
or (val, index)
. It should return the a list of
zero or more new values. See sys::List.flatMap.
If mapping a grid, the mapping function takes (row)
or (row,index)
and returns a list of zero or more new Dict rows. See haystack::Grid.flatMap.
If mapping a stream, the mapping functions takes (val)
. See docHaxall::Streams#flatMap.
Examples:
[1, 2, 3].flatMap(v => [v, v+10]) >> [1, 11, 2, 12, 3, 13]
Static
flattenFlatten a list to a single level. If given a list of grids, then flatten rows to a single grid. Also see sys::List.flatten and haystack::Etc.gridFlatten.
Examples:
// flatten a list of numbers
[1, [2, 3], [4, [5, 6]]].flatten >> [1, 2, 3, 4, 5, 6]
// flatten a list of grids
["Carytown", "Gaithersburg"].map(n=>readAll(siteRef->dis==n)).flatten
Static
foldFold a list or stream into a single value using given
folding function. The folding function signature must be (val, acc)
where val is the items being folded, and acc is an
accumulator used to maintain state between iterations.
Lifecycle of a fold:
fn(foldStart, null)
, return initial accumulator statefn(item, acc)
for every item, return new accumulator
statefn(foldEnd, acc)
return final resultSee docHaxall::Streams#fold for streaming details.
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().
Built-in folding functions include:
Examples:
[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
Also see reduce() which is easier to use if doing your own simple rollup computation.
Static
foldStatic
foldFold 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)
Static
foldThe fold end marker value
Static
foldThe fold start marker value
Static
formatFormat an object using the current locale and specified format pattern. Formatting patterns follow Fantom toLocale conventions:
toLocale
method is found, then return val.toStr
Examples:
123.456kW.format >> 123kW
123.456kW.format("#.0") >> 123.5kW
today().format("D-MMM-YYYY") >> 8-Feb-2023
today().format("DDD MMMM YYYY") >> 8th February 2023
now().format("D-MMM hh:mm") >> 08-Feb 14:50
now().format("DD/MM/YY k:mmaa") >> 08/02/23 2:50pm
Optional
pattern: stringStatic
fromGiven Number of milliseconds since Unix epoch return a DateTime. The epic is defined as 1-Jan-1970 UTC. If timezone is null, use system default. Also see toJavaMillis.
Optional
tz: stringStatic
funcStatic
funcsFind 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.
Examples:
funcs() // all functions
funcs(sparkRule) // match filter
Optional
filterExpr: ExprStatic
getGet an item from a collection:
The get function maybe be accessed using the []
shortcut
operator:
list[3] >> list.get(3)
Static
getGet an item from a str, list, or grid safely when an index is out of bounds:
Static
gridGiven a grid return the types used in each column as a grid with the following:
name
: string name of the columnkind
: all the different value kinds in the column separated
by "|"count
: total number of rows with column with a non-null
value Also see readAllTagNames.Example:
readAll(site).gridColKinds
Static
gridConvert grid columns into a dict of name/val pairs. The
name/val paris are derived from each column using the given
functions. The functions take (col, index)
Example:
// create dict of column name to column dis
read(temp).hisRead(today).gridColsToDict(c=>c.name, c=>c.meta.dis)
Static
gridReplace every grid cell with the given from
value with the to
value. The resulting grid has the same grid and col meta.
Replacement comparison is by via equality via ==
operator,
so it will only replace scalar values or null.
Example:
grid.gridReplace(null, 0) // replace all null cells with zero
grid.gridReplace(na(), 0) // replace all NA cells with zero
Static
gridConvert grid rows into a dict of name/val pairs. The
name/value pairs are derived from each row using the given
functions. The functions take (row, index)
Example:
// create dict of sites with dis:area pairs
readAll(site).gridRowsToDict(s=>s.dis.toTagName, s=>s->area)
Static
hasStatic
hourStatic
hoursStatic
indexReturn 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:
val
is Str, then x
is substring.val
is List, then x
is item to search.Static
indexrReturn 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:
val
is Str, then x
is substring.val
is List, then x
is item to search.Static
insertStatic
insertStatic
isIs number an ASCII alpha char: isUpper||isLower
Examples:
isAlpha("A".get(0)) >> true
isAlpha("a".get(0)) >> true
isAlpha("8".get(0)) >> false
isAlpha(" ".get(0)) >> false
isAlpha("Ã".get(0)) >> false
Static
isIs number an ASCII alpha-numeric char: isAlpha||isDigit
Examples:
isAlphaNum("A".get(0)) >> true
isAlphaNum("a".get(0)) >> true
isAlphaNum("8".get(0)) >> true
isAlphaNum(" ".get(0)) >> false
isAlphaNum("Ã".get(0)) >> false
Static
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isReturn if given string is an Axon keyword
Static
isReturn if a year is a leap year. Year must be four digit Number such as 2020.
Static
isStatic
isIs number an ASCII lowercase alphabetic char: a-z
Examples:
isUpper("a".get(0)) >> true
isUpper("A".get(0)) >> false
isUpper("5".get(0)) >> false
Static
isGiven an optional value return true if the SI metric system should be used. Return false if the United States customary unit system should be used. The following rules are used:
Examples:
isMetric({geoCountry:"US"}) >> false
isMetric({geoCountry:"FR"}) >> true
isMetric(75°F) >> false
isMetric({unit:"Δ°C"}) >> true
isMetric() >> fallback to server locale
Optional
val: JsObjStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isStatic
isIs number is whitespace char: space \t \n \r \f
Examples:
isSpace("x".get(0)) >> false
isSpace(" ".get(0)) >> true
isSpace("\n".get(0)) >> true
Static
isStatic
isStatic
isReturn if the given string is legal tag name - see haystack::Etc.isTagName
Static
isStatic
isIs number an ASCII uppercase alphabetic char: A-Z
Examples:
isUpper("A".get(0)) >> true
isUpper("a".get(0)) >> false
isUpper("5".get(0)) >> false
Static
isStatic
isStatic
isStatic
joinStatic
joinStatic
keepReturn a new grid with keeps the given columns, but removes all the others. Columns can be Str names or Col instances. Also see docHaxall::Streams#keepCols.
Example:
readAll(site).keepCols(["id", "area"])
Static
lastGet the last item from an ordered collection or return null if the collection is empty:
Static
lastDateSpan for month previous to this month 1..28-31
Static
lastGet the last day of the date's month. Also see firstOfMonth().
Example:
2009-10-28.lastOfMonth >> 2009-10-31
Static
lastDateSpan for 3 month quarter previous to this quarter
Static
lastDateSpan for week previous to this week sun..sat
(uses
locale start of week)
Static
lastDateSpan for year previous to this year Jan-1..Dec-31
Static
libsStatic
limitTruncate stream after given limit is reached. See docHaxall::Streams#limit.
Static
localeEvaluate an expression within a specific locale. This enables formatting and parsing of localized text using a locale other than the default for the current context.
Examples:
// format Date in German
localeUse("de", today().format)
// parse Date in German
localeUse("de", parseDate("01 Mär 2021", "DD MMM YYYY"))
Static
lowerConvert a char number or str to ASCII lower case. Also see upper() and decapitalize().
Examples:
lower("CAT") >> "cat"
lower("Cat") >> "cat"
lower(65).toChar >> "a"
Static
makeStatic
mapMap list, dict, or grid by applying the given mapping function.
If mapping a list, the mapping should be a function that
takes (val)
or (val, index)
. It should return the new value
for that index.
If mapping a dict, the mapping should be a function that
takes (val)
or (val, name)
. It should return the new value
for that name.
If mapping a grid, the mapping function takes (row)
or (row,index)
and returns a new dictionary to use for the row. The
resulting grid shares the original's grid level meta.
Columns left intact share the old meta-data, new columns
have no meta-data. If the mapping function returns null,
then that row is removed from the resulting grid (not
mapped).
If mapping a range, then the mapping function takes (integer)
,
and returns a list for each mapped integer inte the range.
If mapping a stream, the mapping functions takes (val)
. See docHaxall::Streams#map.
Examples:
// create list adding ten to each number
[1, 2, 3].map(v => v+10) >> [11, 12, 13]
// create new list that turns strings into uppercase
["ape", "bee", "cat"].map(upper) // ["APE, "BEE", "CAT"]
// create dict adding ten to each value
{a:1, b:2, c:3}.map(v => v+10) >> {a:11, b:12, c:13}
// create grid with just dis, area column
readAll(site).map(s => {dis:s->dis, area:s->area})
Static
markerGet the marker value singleton haystack::Marker.val
Static
maxStatic
mergeStatic
metaStatic
minStatic
minuteStatic
missingStatic
monthStatic
moveFind the given item in a list, and move it to the given index. All the other items are shifted accordingly. Negative indexes may used to access an index from the end of the list. If the item is not found then this is a no op. Return new list.
Examples:
[10, 11, 12].moveTo(11, 0) >> [11, 10, 12]
[10, 11, 12].moveTo(11, -1) >> [10, 12, 11]
Static
naGet NA not-available singleton haystack::NA.val
Static
nameIf val is a Col, get the column name.
Example:
// get name of first column
readAll(site).cols.first.name
Static
namesStatic
nanReturn the Number representation of not-a-number
Static
negReturn the Number representation negative infinity
Static
nowReturn current DateTime according to context's time zone. This function will use a cached version which is only accurate to within 250ms (see sys::DateTime.now for details). Also see nowTicks() and nowUtc().
Static
nowStatic
nowReturn current DateTime in UTC. This function will use a cached version which is only accurate to within 250ms (see sys::DateTime.nowUtc for details). Also see now() and nowTicks().
Static
numStatic
numGet the number of days in a given month. The month parameter may be:
Examples:
numDaysInMonth() >>> days in current month
numDaysInMonth(1) >>> 31day (days in January)
numDaysInMonth(6) >>> 30day (days in June)
numDaysInMonth(2) >>> 28day or 29day (days for Feb this year)
numDaysInMonth(2012-02-13) >>> 29day (days in Feb for leap year)
Optional
month: JsObjStatic
occurredReturn if a timestamp is contained within a Date range. Range may be any value supported by toDateSpan. Timestamp may be either a Date or a DateTime. Also see contains.
Examples:
ts.occurred(thisWeek)
ts.occurred(pastMonth())
ts.occurred(2010-01-01..2010-01-15)
Static
padlPad string to the left. If size is less than width, then add the given char to the left to achieve the specified width.
Examples:
"3".padl(3, "0") >> "003"
"123".padl(2, "0") >> "123"
Optional
char: stringStatic
padrPad string to the right. If size is less than width, then add the given char to the left to acheive the specified with.
Examples:
"xyz".padr(2, ".") >> "xyz"
"xyz".padr(5, "-") >> "xyz--"
Optional
char: stringStatic
parseParse Axon source code into an abstract syntax tree modeled
as a tree of dicts. Each node has a type
tag which
specified the node type. Common AST shapes:
123 => {type:"literal", val:123}
a => {type:"var", name:"a"}
not a => {type:"not", operand:{type:"var", name:"a"}}
a + b => {type:"add", lhs:{type:"var", name:"a"}, rhs:{type:"var", name:"b"}}
NOTE: the keys and structure of the AST is subject to change over time.
Static
parseParse a Str into a Bool, legal formats are "true" or "false. If invalid format and checked is false return null, otherwise throw ParseErr.
Examples:
parseBool("true")
parseBool("bad", false)
Optional
checked: booleanStatic
parseParse a Str into a Date. If the string cannot be parsed into a valid Date and checked is false then return null, otherwise throw ParseErr. See sys::Date.toLocale for pattern.
Examples:
parseDate("7-Feb-23", "D-MMM-YY")
parseDate("07/02/23", "DD/MM/YY")
parseDate("7 february 2023", "D MMMM YYYY")
parseDate("230207", "YYMMDD")
Optional
pattern: stringOptional
checked: booleanStatic
parseParse a Str into a DateTime. If the string cannot be parsed into a valid DateTime and checked is false then return null, otherwise throw ParseErr. See sys::DateTime.toLocale for pattern:
YY Two digit year 07
YYYY Four digit year 2007
M One/two digit month 6, 11
MM Two digit month 06, 11
MMM Three letter abbr month Jun, Nov
MMMM Full month June, November
D One/two digit day 5, 28
DD Two digit day 05, 28
DDD Day with suffix 1st, 2nd, 3rd, 24th
WWW Three letter abbr weekday Tue
WWWW Full weekday Tuesday
V One/two digit week of year 1,52
VV Two digit week of year 01,52
VVV Week of year with suffix 1st,52nd
h One digit 24 hour (0-23) 3, 22
hh Two digit 24 hour (0-23) 03, 22
k One digit 12 hour (1-12) 3, 11
kk Two digit 12 hour (1-12) 03, 11
m One digit minutes (0-59) 4, 45
mm Two digit minutes (0-59) 04, 45
s One digit seconds (0-59) 4, 45
ss Two digit seconds (0-59) 04, 45
SS Optional seconds (only if non-zero)
f* Fractional secs trailing zeros
F* Fractional secs no trailing zeros
a Lower case a/p for am/pm a, p
aa Lower case am/pm am, pm
A Upper case A/P for am/pm A, P
AA Upper case AM/PM AM, PM
z Time zone offset Z, +03:00 (ISO 8601, XML Schema)
zzz Time zone abbr EST, EDT
zzzz Time zone name New_York
'xyz' Literal characters
'' Single quote literal
Examples:
parseDateTime("2023-02-07 14:30", "YYYY-MM-DD hh:mm")
parseDateTime("2023-02-07 14:30", "YYYY-MM-DD hh:mm", "Paris")
parseDateTime("7/2/23 2:30pm", "D/M/YY k:mma")
parseDateTime("2023-02-07T14:30:00", "YYYY-MM-DD'T'hh:mm:ss")
Optional
pattern: stringOptional
tz: stringOptional
checked: booleanStatic
parseStatic
parseParse a Str into a Float. Representations for infinity and not-a-number are "-INF", "INF", "NaN". If invalid format and checked is false return null, otherwise throw ParseErr. This string value cannot include a unit (see parseNumber).
Examples:
parseFloat("123.456").format("0.000")
parseFloat("NaN")
parseFloat("INF")
Optional
checked: booleanStatic
parseParse a Str into a integer number using the specified radix. If invalid format and checked is false return null, otherwise throw ParseErr. This string value cannot include a unit (see parseNumber).
Examples:
parseInt("123")
parseInt("afe8", 16)
parseInt("10010", 2)
Optional
radix: NumberOptional
checked: booleanStatic
parseParse a Str into a number with an option unit. If invalid format and checked is false return null, otherwise throw ParseErr. Also see parseInt and parseFloat to parse basic integers and floating point numbers without a unit.
Examples:
parseNumber("123")
parseNumber("123kW")
parseNumber("123.567").format("#.000")
Optional
checked: booleanStatic
parseParse a Str into a Ref. If the string is not a valid Ref identifier then raise ParseErr or return null based on checked flag. If the string has a leading "@", then it is stripped off before parsing.
Examples:
parseRef("abc-123")
parseRef("@abc-123")
Optional
dis: JsObjOptional
checked: booleanStatic
parseParse a search string into a Filter instance. The resulting filter can then be used with read(), readAll(), filter(), or filterToFunc().
The search string is one of the following free patterns:
*<glob>*
case insensitive glob with ? and * wildcards
(default)re:<regex>
regular expressionf:<filter>
haystack filterSee docFresco::Nav#searching for additional details on search syntax.
Examples:
readAll(parseSearch("RTU-1"))
readAll(point).filter(parseSearch("RTU* Fan"))
Static
parseParse a Str into a Symbol. If the string is not a valid Symbol identifier then raise ParseErr or return null based on checked flag. The string must not include a leading "^".
Examples:
parseSymbol("func:now")
Optional
checked: booleanStatic
parseParse a Str into a Time. If the string cannot be parsed into a valid Time and checked is false then return null, otherwise throw ParseErr. See sys::Time.toLocale for pattern.
Examples:
parseTime("14:30", "h:mm")
parseTime("2:30pm", "k:mma")
parseTime("2:30:00pm", "k:mm:ssa")
Optional
pattern: stringOptional
checked: booleanStatic
parseParse a Str into a standardized unit name. If the val is not a valid unit name from the standard database then return null or raise exception based on checked flag.
Examples:
parseUnit("%")
parseUnit("percent")
Optional
checked: booleanStatic
parseParse a string into a Uri instance. If the string cannot be parsed into a valid Uri and checked is false then return null, otherwise throw ParseErr. This function converts an URI from standard form. Use uriDecode to convert a string from escaped form. See sys::Uri for a detailed discussion on standard and escaped forms.
Examples:
"foo bar".parseUri >> `foo bar`
"foo%20bar".uriDecode >> `foo bar`
Optional
checked: booleanStatic
pastDateSpan for last 30days today-30days..today
Static
pastDateSpan for last 7 days as today-7days..today
Static
pastDateSpan for this past today-365days..today
Static
posReturn the Number representation positive infinity
Static
reduceReduce a collection to a single value with the given reducer
function. The given function is called with each item in
the collection along with a current accumulation value. The
accumation value is initialized to init
for the first item,
and for every subsequent item it is the result of the
previous item. Return the final accumulation value. Also
see fold which is preferred if doing standard
rollup such as sum or average.
If working with a list, the function takes (acc, val, index)
and returns accumulation value
If working with a grid, the function takes (acc, row, index)
and returns accumulation value
If working with a stream, then function takes (acc, val)
and
returns accumulation value See docHaxall::Streams#reduce.
Examples:
[2, 5, 3].reduce(0, (acc, val)=>acc+val) >> 10
[2, 5, 3].reduce(1, (acc, val)=>acc*val) >> 30
Static
refStatic
refGenerate a new unique Ref identifier
Static
reStatic
reStatic
refGiven an absolute ref, return its project name. If the ref is not formatted as "p:proj:r:xxx", then raise an exception or return null based on the checked flag:
Examples:
refProjName(@p:demo:r:xxx) >> "demo"
refProjName(@r:xxx) >> raises exception
refProjName(@r:xxx, false) >> null
Optional
checked: booleanStatic
reReturn a list of the substrings captured by matching the
given regular operation against s
. Return null if no
matches. The first item in the list is the entire match,
and each additional item is matched to ()
arguments in the
regex pattern. See AxonUsage.
Examples:
re: r"(RTU|AHU)-(\d+)"
reGroups(re, "AHU") >> null
reGroups(re, "AHU-7") >> ["AHU-7", "AHU", "7"]
Static
relStatic
reStatic
removeStatic
removeReturn a new grid with the given column removed. If the column doesn't exist, then return given grid. Also see docHaxall::Streams#removeCol.
Static
removeReturn a new grid with all the given columns removed. Columns can be Str names or Col instances. Also see docHaxall::Streams#removeCols.
Static
removeGet the remove value singleton haystack::Remove.val
Static
renameStatic
renameStatic
reorderReturn a new grid with the columns reordered. The given list of names represents the new order and must contain the same current column names. Any columns not specified are removed. Also see colNames, moveTo, and docHaxall::Streams#reorderCols.
Example:
// move name to first col, and foo to last col
cols: grid.colNames.moveTo("name", 0).moveTo("foo", -1)
return grid.reorderCols(cols)
Static
replaceString replace of all occurrences of from
with to
. All three
parameters must be strings.
Examples:
"hello".replace("hell", "t") >> "to"
"aababa".replace("ab", "-") >> "a--a"
Static
rowGet a grid row as a list of cells. Sparse cells are included as null. Also see colToList().
Example:
readAll(equip).first.rowToList
Static
secondStatic
setStatic
setReturn a new grid with column meta-data replaced by given meta dict. If column not found, then return given grid. Also see addColMeta and docHaxall::Streams#setColMeta.
Static
setReturn new grid with grid level meta-data replaced by given meta Dict. Also see addMeta and docHaxall::Streams#setMeta.
Example:
read(temp).hisRead(today).setMeta({view:"table"})
Static
sizeStatic
skipSkip the given number of items in a stream. See docHaxall::Streams#skip.
Static
sortSort a list or grid.
If sorting a list, the sorter should be a function that
takes two list items and returns -1, 0, or 1 (typicaly done
with the <=>
operator. If no sorter is passed, then the
list is sorted by its natural ordering.
If sorting a grid, the sorter can be a column name or a function. If a function, it should take two rows and return -1, 0, or 1.
Examples:
// sort string list
["bear", "cat", "apple"].sort
// sort string list by string size
["bear", "cat", "apple"].sort((a,b) => a.size <=> b.size)
// sort sites by area
readAll(site).sort((a, b) => a->area <=> b->area)
Static
sortSort a grid by row display name - see haystack::Grid.sortDis
Examples:
// read all sites and sort by display name
readAll(site).sortDis
Static
sortrStatic
splitSplit a string by the given separator and trim whitespace.
If sep
is null then split by any whitespace char; otherwise
it must be exactly one char long. See sys::Str.split
for detailed behavior.
Options:
Examples:
"a b c".split >> ["a", "b", "c"]
"a,b,c".split(",") >> ["a", "b", "c"]
"a, b, c".split(",") >> ["a", "b", "c"]
"a, b, c".split(",", {noTrim}) >> ["a", " b", " c"]
Optional
sep: stringOptional
opts: DictStatic
spreadStatic
startStatic
startReturn current locale's start of weekday. Weekday is returned as integer from 0 (Sunday) to 6 (Saturday).
Static
startsReturn if Str starts with the specified Str.
Examples:
"hi there".startsWith("hi") >> true
"hi there".startsWith("foo") >> false
Static
streamCreate new stream from given collection:
Static
streamCreate a new stream for the cell values of the given column. See docHaxall::Streams#streamCol.
Static
sumStatic
swizzleGiven a grid of records, assign new ids and swizzle all
internal ref tags. Each row of the grid must have an id
tag. A new id is generated for each row, and any Ref tags
which used one of the old ids is replaced with the new id.
This function is handy for copying graphs of recs such as
site/equip/point trees.
Static
tagsStatic
termsStatic
thisDateSpan for this month as 1st..28-31
Static
thisDateSpan for this 3 month quarter
Static
thisDateSpan for this week as sun..sat
(uses locale start of
week)
Static
thisDateSpan for this year Jan-1..Dec-31
Static
timeIf val is a DateTime: get time portion of the timestamp. If val is a Number: construct a time instance from hour, minutes, secs (truncated to nearest second).
Examples:
now().time // current time
time(20, 45) // same as 20:45
Static
timesStatic
toConvert a number to the given unit. If the units are not of the same dimension then an exception is raised. The target unit can be a string or a Number. If target unit is a Number, then the scalar value is ignored, but by convention should be 1. Also see as() function to set a unit without conversion.
Examples:
10kWh.to(1BTU)
10kWh.to("BTU")
75°F.to(1°C)
to(75°F, 1°C)
Static
toStatic
toConvert a unicode char number into a single char string
Examples:
toChar(65) >> "A"
Static
toConvert the following objects into a haystack::DateSpan:
Func
: function which evaluates to date rangeDateSpan
: return itselfDate
: one day rangeSpan
: return haystack::Span.toDateSpanStr
: evaluates to haystack::DateSpan.fromStrDate..Date
: starting and ending date (inclusive)Date..Number
: starting date and num of days (day unit
required)DateTime..DateTime
: use starting/ending dates; if end is
midnight, then use previous dateNumber
: convert as yearExamples:
toDateSpan(2010-07-01..2010-07-03) >> 01-Jul-2010..03-Jul-2010
toDateSpan(2010-07-01..60day) >> 01-Jul-2010..29-Aug-2010
toDateSpan(2010-07) >> 01-Jul-2010..31-Jul-2010
toDateSpan(2010) >> 01-Jan-2010..31-Dec-2010
toDateSpan(pastWeek) // on 9 Aug >> 02-Aug-2010..09-Aug-2010
Static
todayReturn today's Date according to context's time zone
Static
toGiven an arbitrary object, translate it to a Grid via haystack::Etc.toGrid:
Example:
// create simple grid with dis,age cols and 3 rows:
[{dis:"Bob", age:30},
{dis:"Ann", age:40},
{dis:"Dan", age:50}].toGrid
Static
toStatic
toGiven a DateTime return Number of milliseconds since Unix epoch. The epic is defined as 1-Jan-1970 UTC. Also see fromJavaMillis.
Static
toStatic
toGet the localized string for the given tag name or qualified name. If the key is formatted as "pod::name" then route to sys::Env.locale, otherwise to haystack::Etc.tagToLocale.
Static
toStatic
toConvert the following objects into a haystack::Span:
Span
: return itselfSpan+tz
: update timezone using same dates only if aligned to
midnightStr
: return haystack::Span.fromStr
using current timezoneStr+tz
: return haystack::Span.fromStr
using given timezoneDateTime..DateTime
: range of two DateTimesDate..DateTime
: start day for date until the end timestampDateTime..Date
: start timestamp to end of day for end dateDateTime
: span of a single timestampDateSpan
: anything accepted by toDateSpan
in current timezoneDateSpan+tz
: anything accepted by toDateSpan
using given timezoneOptional
tz: stringStatic
toGiven arbitrary string, convert to a safe tag name - see haystack::Etc.toTagName
Static
toStatic
transposeStatic
trimTrim whitespace from the beginning and end of the string.
For the purposes of this function, whitespace is defined as
any character equal to or less than the 0x20 space character
(including
, \r
, \n
, and \t
).
Examples:
" abc ".trim >> "abc"
"abc".trim >> "abc"
Static
trimTrim whitespace only from the end of the string. See trim for definition of whitespace.
Examples:
" abc ".trimEnd >> " abc"
"abc".trimEnd >> "abc"
Static
trimTrim whitespace only from the beginning of the string. See trim for definition of whitespace.
Examples:
" abc ".trimStart >> "abc "
"abc".trimStart >> "abc"
Static
tzStatic
uniqueReturn the unique items in a collection. If val is a List then return sys::List.unique. If val is a Grid then return haystack::Grid.unique where key must be a column name or list of column names.
Examples:
[1, 1, 2, 2].unique >> [1, 2]
grid.unique("geoState") >> unique states
grid.unique(["geoCity", geoState"]) >> city,state combos
Static
unitGiven a number return its unit string or null. If the val is null, then return null.
Static
unitsStatic
upperConvert a char number or str to ASCII upper case. Also see lower() and capitalize().
Examples:
upper("cat") >> "CAT"
upper("Cat") >> "CAT"
upper(97).toChar >> "A"
Static
uriGet the basename (last name in path without extension) of a Uri as a string.
Static
uriParse an ASCII percent encoded string into a Uri according
to RFC 3986. All %HH escape sequences are translated into
octects, and then the octect sequence is UTF-8 decoded into
a Str. The +
character in the query section is unescaped
into a space. If checked if true then throw ParseErr if the
string is a malformed URI or if not encoded correctly,
otherwise return null. Use parseUri to
parse from standard form. See sys::Uri for
a detailed discussion on standard and encoded forms.
Examples:
"foo bar".parseUri >> `foo bar`
"foo%20bar".uriDecode >> `foo bar`
Optional
checked: booleanStatic
uriReturn the percent encoded string for this Uri according to
RFC 3986. Each section of the Uri is UTF-8 encoded into
octects and then percent encoded according to its valid
character set. Spaces in the query section are encoded as +
.
Examples:
`foo bar`.uriEncode >> "foo%20bar"
Static
uriStatic
uriReturn if the fragment identifier portion of the a URI after hash symbol
Static
uriStatic
uriStatic
uriStatic
uriStatic
uriStatic
uriStatic
uriStatic
uriStatic
uriStatic
valsStatic
weekdayStatic
weekStatic
xstrStatic
yearStatic
yesterdayReturn yesterday's Date according to context's time zone
System library