Spec-Zone.ru › ColdFusion

structReduce

Iterates over every entry of the struct and calls the closure to work on the key value pair of the struct. This function will reduce the struct to a single value and will return the value.

structReduce(struct, function(result, key, value [,struct]){} [, initialVal]) → returns any

Member Function Syntax

someStruct.reduce(function(result, key, value [,struct]){} [, initialVal])

  • CF11+
  • Lucee
  • BL 1.0.0+
  • See Also: structEach structSome structMap structFilter

    Argument Reference

    struct struct
    Required

    The input struct.

    callback any
    Required

    Closure or a function reference that will be called for each of the iteration.

    Callback parameters:

    • result* any : The result of the reduce operation after the previous iteration
    • key* string : The key for the current iteration
    • value* any : The value for the current iteration
    • struct* struct : A reference of the original struct

    initialVal any

    Initial value which will be used for the reduce operation.

    Links more information about structReduce

    • Map, Reduce and other Higher Order Functions - A Primer for map, reduce, filter, and Higher Order Functions in general.
    • ColdFusion 11: .map() and .reduce() - A look at the new .map() and .reduce() methods that each of array, struct and lists all have

    Examples
    Sample code invoking the structReduce function

    Script Syntax

    rainbow = { "Red"="Whero",  "Orange"="Karaka", "Yellow"="Kowhai",  "Green"="Kakariki" }; 
      ui = structReduce(  rainbow, function(previousValue, key, value) 
       { 
     return previousValue & "<dt>#key#</dt><dd>#value#</dd>"; 
      }, 
     "<dl>" 
     ) & "</dl>"; 
     writeDump(rainbow); 
     writeOutput(ui); 
    

    Using Member Function

    CF 11+ Lucee 4.5+

    rainbow = { "Red"="Whero",  "Orange"="Karaka", "Yellow"="Kowhai",  "Green"="Kakariki" }; 
      ui = rainbow.reduce( function(previousValue, key, value) 
       { 
     return previousValue & "<dt>#key#</dt><dd>#value#</dd>"; 
      }, 
     "<dl>" 
     ) & "</dl>"; 
     writeDump(rainbow); 
     writeOutput(ui); 
    

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/structreduce

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API