How to reject values in a CDT array on the basis of a condition?

Hi All,

I want to reject values in a CDT array on the basis of a condition.

For ex - I have a CDT array of type, suppose, type!someType(a,b), where a and b are fields in CDT. Now, My array looks like below:

{

type!someType(a: 1, b: null)

type!someType(a: null, b: 1)

type!someType(a: null, b: null)

},

I want to filter this array and get only those CDT values where a <> null.

What can be the possible way to do it?

  Discussion posts and replies are publicly visible

Parents
  • Try something like this.  Note in the wherecontains() you may have to change the apply(fn!tointeger..) to match your data type, as wherecontains() is type-sensitive.

    a!localVariables(
      local!data: {
        {a: 1, b: null},
        {a: null, b: null},
        {a: null, b: 1},
        {a: 1, b: 2},
        {a: 2, b: null}
      },
      
      index(
        local!data,
        wherecontains(
          reject(
            fn!isnull,
            local!data.a
          ),
          apply(fn!tointeger,local!data.a)
        )
      )
    )

Reply
  • Try something like this.  Note in the wherecontains() you may have to change the apply(fn!tointeger..) to match your data type, as wherecontains() is type-sensitive.

    a!localVariables(
      local!data: {
        {a: 1, b: null},
        {a: null, b: null},
        {a: null, b: 1},
        {a: 1, b: 2},
        {a: 2, b: null}
      },
      
      index(
        local!data,
        wherecontains(
          reject(
            fn!isnull,
            local!data.a
          ),
          apply(fn!tointeger,local!data.a)
        )
      )
    )

Children