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 sauravk,

    apply( )-Calls a rule or function for each item in a list, and provides any contexts specified.

    Ex: apply(fn!sum, {1, 2, 3}, 2) returns 3; 4; 5 This is the simple example for apply function.

    forEach( )- Evaluates the provided expression once for every item and returns an array of the results.
    Ex:
    a!forEach(
    items: {"January", "February", "March"},
    expression: with(
    local!month: fv!item,
    a!forEach(
    items: {1, 2},
    expression: local!month & " " & fv!item
    )
    )
    )

    output: {"January 1", "January 15"}, {"February 1", "February 15"}, and {"March 1", "March 15"}

    applyComponents: calls a rule for each item in an array and returns an array of the results.
    a!applyComponents() is applicable when you're iterating over a list of components or iterating over a rule that has a load() within it,

    Ex: a!applyComponents(
    function: fn!isnull,
    array: {
    1,
    5,
    null,
    6,
    null,
    8
    }
    )

    O/p:
    false false true false true false

    Thanks,
    ravalik
Reply
  • Hi sauravk,

    apply( )-Calls a rule or function for each item in a list, and provides any contexts specified.

    Ex: apply(fn!sum, {1, 2, 3}, 2) returns 3; 4; 5 This is the simple example for apply function.

    forEach( )- Evaluates the provided expression once for every item and returns an array of the results.
    Ex:
    a!forEach(
    items: {"January", "February", "March"},
    expression: with(
    local!month: fv!item,
    a!forEach(
    items: {1, 2},
    expression: local!month & " " & fv!item
    )
    )
    )

    output: {"January 1", "January 15"}, {"February 1", "February 15"}, and {"March 1", "March 15"}

    applyComponents: calls a rule for each item in an array and returns an array of the results.
    a!applyComponents() is applicable when you're iterating over a list of components or iterating over a rule that has a load() within it,

    Ex: a!applyComponents(
    function: fn!isnull,
    array: {
    1,
    5,
    null,
    6,
    null,
    8
    }
    )

    O/p:
    false false true false true false

    Thanks,
    ravalik
Children
No Data