Member Functions introduced in ColdFusion (2018 release)

July 12, 2018
Newbie 3 posts
Followers: 0 people
5

Member Functions introduced in ColdFusion (2018 release)

Newbie 3 posts
Followers: 0 people
July 12, 2018

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)
  • 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()
  • var.precisionEvaluate(expr)

Date Member Functions

  • dateVar.format()

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>
Comments (5)
2018-07-31 07:48:12
2018-07-31 07:48:12

Hi Ashudeep,

Very nice post! Couple comments:

1) format() is, thankfully, just a member function (not BIF)
2) precisionEvaluate() is also a numeric member function (useful for converting to java.math.BigDecimal) Ex:

myVar1 = 10;
myVar2 = myVar1.precisionEvaluate();//converts to java.math.BigDecimal (good!)
writeOutput(myVar1.getClass().getName() & ‘ ‘ & myVar2.getClass().getName());

Outputs “java.lang.Integer java.math.BigDecimal” Sweet!! Thanks Adobe!! ..now for CF to internally use BigDecimal to reduce floating point math issues/tickets =)

Thanks!,
-Aaron

Like
(4)
>
Aaron Neff
's comment
2018-08-02 09:06:57
2018-08-02 09:06:57
>
Aaron Neff
's comment

Thanks Aaron for the feedback, i have corrected it in the blog post.

Like
>
Aaron Neff
's comment
2018-10-10 10:19:44
2018-10-10 10:19:44
>
Aaron Neff
's comment

Two function names contain character x followed by an opening bracket. This is presented as a smiley on this page X(

Like
>
Bernhard Döbler
's comment
2018-10-29 06:28:39
2018-10-29 06:28:39
>
Bernhard Döbler
's comment

Yeah, it was conflicting with the smileys, i have corrected that. Thanks for reporting.

Like
(1)
>
Aaron Neff
's comment
2018-10-29 15:42:53
2018-10-29 15:42:53
>
Aaron Neff
's comment

I like that some of the examples have semicolon and some don’t. That was a good new feature too.

Like
Add your comment