Difference b/w apply(),applyComponent,For Each loop

Hi ,

 

Can anyone share some good example to differentiate b/w apply(),applyComponent,For Each loop.

 

Please don't share any documentation link as i am not getting clarity by seeing that.

 

If possible plz use any small dataset to give an example. This always confuse which one i should use on what scenario.

 

  Discussion posts and replies are publicly visible

Parents
  • Hi,

    apply() :
    Calls a rule or function for each item in a list, and provides any contexts specified.
    apply(fn!sumsq, {1,2,3},10)
    It returns the output as
    101
    104
    109
    apply() cannot be used with rules or functions that store local data, including rules using load() and certain interface components. In these cases, apply() will return an error. In these cases, use a!applyComponents().


    a!applyComponents() :
    Calls a rule or function for each item in a list and supports the preservation of the local state on interfaces.
    load(
    local!stateTokens,
    a!applyComponents(
    function: fn!sumsq,
    array: ri!num,
    arrayVariable: local!stateTokens
    )
    )
    It returns the output as
    1
    4
    9
    applyComponents() preserves the local state while apply cannot.

    a!foreach() :
    a!foreach() is also a looping function
    In previous versions it was not their so we have to go with apply() and a!applyComponents(),
    from 17.2 version we have a!foreach() ,it will do every thing which apply() and a!applyComponents() does but with easier syntax, better null handling, and streamlined support of SAIL components.

    a!forEach(items: {1, 2, 3}, expression: fv!item + 10)
    It returns the output as
    11
    12
    13
    Once go through this link for more information about it.
    docs.appian.com/.../fnc_looping_a_foreach.html

    and check this previous discussion
    community.appian.com/.../what-is-the-difference-between-apply-applycomponents-and-foreach

    I hope , it will help you..

    Regards
    Aswini

Reply
  • Hi,

    apply() :
    Calls a rule or function for each item in a list, and provides any contexts specified.
    apply(fn!sumsq, {1,2,3},10)
    It returns the output as
    101
    104
    109
    apply() cannot be used with rules or functions that store local data, including rules using load() and certain interface components. In these cases, apply() will return an error. In these cases, use a!applyComponents().


    a!applyComponents() :
    Calls a rule or function for each item in a list and supports the preservation of the local state on interfaces.
    load(
    local!stateTokens,
    a!applyComponents(
    function: fn!sumsq,
    array: ri!num,
    arrayVariable: local!stateTokens
    )
    )
    It returns the output as
    1
    4
    9
    applyComponents() preserves the local state while apply cannot.

    a!foreach() :
    a!foreach() is also a looping function
    In previous versions it was not their so we have to go with apply() and a!applyComponents(),
    from 17.2 version we have a!foreach() ,it will do every thing which apply() and a!applyComponents() does but with easier syntax, better null handling, and streamlined support of SAIL components.

    a!forEach(items: {1, 2, 3}, expression: fv!item + 10)
    It returns the output as
    11
    12
    13
    Once go through this link for more information about it.
    docs.appian.com/.../fnc_looping_a_foreach.html

    and check this previous discussion
    community.appian.com/.../what-is-the-difference-between-apply-applycomponents-and-foreach

    I hope , it will help you..

    Regards
    Aswini

Children
No Data