enumerate

Certified Senior Developer

Another technical question on how  enumerate works. Can some one explain

index({10,30,40,50,60,70},enumerate(5),{})

returns

10; 20; 20; 30; 40

Expected out 

10; 20; 30; 40

But same works with below std code , but not sure why?

index({10,20,30,40,50,60,70},enumerate(5)+1,{})

output :

10; 20; 30; 40; 50

Syntax

enumerate(n)

Returns a list of integer numbers from 0 through n-1.
Returns: List of Number (Integer)
n (Number (Integer)): The number of integer numbers to return.

  Discussion posts and replies are publicly visible

Parents
  • enumerate(n) returns a list of integer numbers from 0 through n-1
    enumerate(0) returns empty number list {}.
    enumerate(1) returns {0}
    enumerate(2) returns {0,1}
    enumerate(3) returns {0,1,2}
    enumerate(4) returns {0,1,2,3}
    and so on.

    In your example the index is not returning as expected.
    Enumerate returns integer list starting from 0 and array/list index starts from 1 in Appian. When index() gets invalid index (<=0) is returns whatever listed as default value.
    index({10,20,30,40,50,60,70},enumerate(5),{}) = index({10,20,30,40,50,60,70},{0,1,2,3,4},{}) returning invalid list of numbers {10,20,20,30,40}
    index({10,20,30,40,50,60,70},enumerate(5) + 1,{}) = index({10,20,30,40,50,60,70},{1,2,3,4,5},{}) returning valid list of numbers {10,20,30,40,50}
    index({10,20,30,40,50,60,70},enumerate(5),1) = index({10,20,30,40,50,60,70},{0,1,2,3,4},1) returning valid list of numbers {1,10,20,30,40}

    index({10,20,30,40,50,60,70},enumerate(5),null) returns valid list of numbers {null,10,20,30,40}

    {10,20,30,40,50,60,70} is auto casted to List of Number (Integer) where a {} is casted to List of Variant. When returning index always returns the type array input. Merging list of variant and integer ending up with unexpected list.
Reply
  • enumerate(n) returns a list of integer numbers from 0 through n-1
    enumerate(0) returns empty number list {}.
    enumerate(1) returns {0}
    enumerate(2) returns {0,1}
    enumerate(3) returns {0,1,2}
    enumerate(4) returns {0,1,2,3}
    and so on.

    In your example the index is not returning as expected.
    Enumerate returns integer list starting from 0 and array/list index starts from 1 in Appian. When index() gets invalid index (<=0) is returns whatever listed as default value.
    index({10,20,30,40,50,60,70},enumerate(5),{}) = index({10,20,30,40,50,60,70},{0,1,2,3,4},{}) returning invalid list of numbers {10,20,20,30,40}
    index({10,20,30,40,50,60,70},enumerate(5) + 1,{}) = index({10,20,30,40,50,60,70},{1,2,3,4,5},{}) returning valid list of numbers {10,20,30,40,50}
    index({10,20,30,40,50,60,70},enumerate(5),1) = index({10,20,30,40,50,60,70},{0,1,2,3,4},1) returning valid list of numbers {1,10,20,30,40}

    index({10,20,30,40,50,60,70},enumerate(5),null) returns valid list of numbers {null,10,20,30,40}

    {10,20,30,40,50,60,70} is auto casted to List of Number (Integer) where a {} is casted to List of Variant. When returning index always returns the type array input. Merging list of variant and integer ending up with unexpected list.
Children
No Data