Whatever message this page gives is out now! Go check it out!
structMap(struct, function(key, value [,struct]){} [, parallel] [, maxThreadCount])Parameter | Req/Opt | Description |
struct | Required | The input struct. |
function | Required | Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are
|
parallel | Optional | True if you want to enable parallel programming. |
maxThreadCount | Optional | The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
<cfscript>
myStruct=StructNew();
myStruct = {a:1,b=2,c=3,d=4,e=5,f=6};
WriteOutput("The input struct is:");
WriteDump(myStruct);
myMap=StructMap(myStruct,function(key,value){
return #value#^2;// Return squared values of struct members
});
WriteOutput("The output struct is:");
WriteDump(myMap); // Writes a new struct with squared values
</cfscript><cfscript>
myStruct = {a:1,b=2,c=3,d=4,e=5,f=6};
myNewMap=myStruct.map(function(key,value){
return value*5;
});
WriteDump(myNewMap);
</cfscript><cfscript>
mystruct= Structnew("ordered");
for(i=1;i<=10000;i++){
mystruct.insert("key#i#","val#i#")
}
function callback(key,val){
return val = val & "struct123"
}
s = mystruct.map(callback,false)
writeoutput(s['key1'] & "<br>")
s = mystruct.map(callback,true);
writeoutput(s['key1'] & "<br>")
s= mystruct.map(callback,true,10)
writeoutput(s['key1'] & "<br>")
s= structmap(struct=mystruct,callback=callback,parallel=true,maxthreadcount=20)
writeoutput(s['key1'] & "<br>")
s = structmap(struct=mystruct,callback=callback,parallel=true,maxthreadcount=40)
writeoutput(s['key1'] & "<br>")
try {
structmap(struct=mystruct,callback=callback,parallel=true,maxthreadcount=-20)
}
catch(any e){
writeoutput("<br>Type: " & e.type & " Message:" & e.message )
}
try{
structmap(struct=mystruct,callback=callback,parallel=true,maxthreadcount=200)
}
catch(any e){
writeoutput("<br>Type: " & e.type & " Message:" & e.message )
}
</cfscript>