Member Functions introduced in ColdFusion (2018 release)

In the 2018 release of ColdFusion, we have introduced new Built-In Functions(BIF) to manipulate different objects using a single line invocation.

  • Query Functions
    • QueryDeleteRow( Object query, int rowNum )
    • QueryDeleteColumn( Object query, String columnName)
  • Arrays Functions
    • ArrayFirst(List list)
    • ArrayLast(List list)
  • Date Functions
    • format(Date date)
    • format (Date date, String mask)
    • format (Date date, String mask, String timeZone)
  • XML Functions
    • XmlIsEmpty( XmlNodeList xmlNodeList )
    • XmlCount( XmlNodeList xml )
    • XmlAppend( XmlNodeList xml1, XmlNodeList xml2 )
    • XmlUpdate( XmlNodeList xml, String key, Object value )
    • XmlKeyList( XmlNodeList xml )
    • XmlKeyArray( XmlNodeList xml )
  • Async Functions
    • RunAsync()
    • RunAsync(UDFMethod method)
    • RunAsync(UDFMethod method, long timeOut)

Numeric Member Functions: We have introduced equivalent Member functions for the following numeric functions.

  • var.abs()
  • var.aCos()
  • var.aSin()
  • var.atn()
  • var.bitAnd(number2)
  • var.bitMaskClear(start, length)
  • var.bitMaskRead(start, length)
  • var.bitMaskSet(mask, start, length)
  • var.bitNot()
  • var.bitOr(number2)
  • var.bitSHLN(count)
  • var.bitXor(number2)
  • var.ceiling()
  • var.cos()
  • var.decrementValue()
  • var.exp()
  • var.fix()
  • var.floor()
  • var.formatBaseN(radix)
  • var.incrementValue()
  • var.log()
  • var.log10()
  • var.max(number)
  • var.min(number)
  • var.round()
  • var.sgn()
  • var.sin()
  • var.sqr()
  • var.tan()

Apart from adding these functions, we have enhanced member functions to return meaningful values so as to enhance in Member Functions Chaining.

  • Array
    • arrayObj.clear()
    • arrayObj.deleteAt()
    • arrayObj.delete()
    • arrayObj.deleteNoCase()
    • arrayObj.insertAt()
    • arrayObj.prepend()
    • arrayObj.resize()
    • arrayObj.set()
    • arrayObj.sort()
    • arrayObj.swap()
  • Struct
    •  structObj.delete()
    • structObj.insert()
    • structObj.update()
  • Async Member Functions
    • then(UDFMethod method)
    • then(UDFMethod method, long timeout)
    • error(UDFMethod method)
    • error(UDFMethod method, long timeout)
    • get()
    • get(long timeout)
    • cancel()
    • isCancelled()
    • isDone()

One can use this feature to write compact code, some examples are as follows:

<cfscript>
myarray=ArrayNew(1);
new_arr= myarray.clear().Resize(10).set(1,10,"blah");
writedump(new_arr);
</cfscript>

<cfscript>
ordered_struct=["key1":"val1","key2":"val2"]
unordered_struct={"key3":"val3","key4":"val4"}
new_struct=unordered_struct.append(ordered_struct).update("key4","updated val4").insert("key5","inserted val5");
writedump(new_struct);
writedump(unordered_struct);
</cfscript>

<cfscript>
myResult=QueryExecute(("SELECT * FROM ORDERS WHERE ORDERID BETWEEN :low AND :high"),{low=1,high=23},
{datasource="cfartgallery"});
// chaining methods
a=myResult.deleteColumn("PHONE").filter(function(item){
return item.STATE=="CO" || item.STATE=="CA";
}).valueArray("TOTAL");
WriteDump(a);
// use reduce function to calculate sum of all prices
red=a.reduce(function(prev,next){
return prev+next; // sum of all prices
},0);
writeoutput(red);
</cfscript>

Leave a reply

Related