Spec-Zone.ru › ColdFusion

structMap

Iterates over every entry of the Struct and calls the closure function to work on the key value pair of the struct. The returned value will be set for the same key in a new struct and the new struct will be returned.

structMap(struct, function(key, value [,struct]){} [, parallel] [, maxThreads]) → returns struct

Member Function Syntax

someStruct.map(function(key, value [,struct]){} [, parallel] [, maxThreads])

  • CF11+
  • Lucee4.5+
  • BL 1.0.0+
  • See Also: structEach structSome structReduce 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:

    • key* string : The key for the current iteration
    • value* any : The value for the current iteration
    • struct* struct : A reference of the original struct

    parallel boolean
    Default: false

    Lucee 4.5+ true if the items can be executed in parallel
    Values:
    • true
    • false

    maxThreads numeric
    Default: 20

    Lucee 4.5+ the maximum number of threads to use when parallel = true

    Links more information about structMap

    • 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 structMap function

    Script Syntax

    original = {
        "one": {
            1: "tahi"
        },
        "two": {
            2: "rua"
        },
        "three": {
            3: "toru"
        },
        "four": { 
            4: "wha"
        }
    };
    function mapOriginal(k,v) {
        return v[ListFirst(v.keyList())];
    }
    fixed = structMap(original,mapOriginal);
    writeDump([original, fixed]);

    Using Member Function

    CF 11+ Lucee 4.5+

    original = {
        "one": {
            1: "tahi"
        },
        "two": {
            2: "rua"
        },
        "three": {
            3: "toru"
        },
        "four": {
            4: "wha"
        }
    };
    fixed = original.map(function(k,v) {
        return v[ListFirst(v.keyList())];
    });
    writeDump([original, fixed]);

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

    Spec-Zone.ru

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