Bibek Kr. Bazaz
Bibek Kr. Bazaz

Reputation: 545

Mule 4 : Dataweave 2.0 : is there any alternative of Java 8 Streams anyMatch() method in Dataweave 2.0?

Scenario : Given an array consisting of objects representing a students marks and role in various subjects, I want to filter and see if there are any subjects where a particular student failed.

var sampleArray = [
    {
        "studentName" : "ABC",  
        "studentsMarks" = [
            {
                "subject" : "maths",
                "marks" : "50"
            },
            {
                "subject" : "science",
                "marks" : "30"
            }
        ]
    },
    {
        "studentName" : "XYZ",  
        "studentsMarks" = [
            {
                "subject" : "maths",
                "marks" : "90"
            },
            {
                "subject" : "science",
                "marks" : "50"
            }
        ]
    }
]

To perform the operation I am doing this :

sizeOf((sampleArray.studentsMarks filter ($.marks < 45))) > 0

this shall return me if there are any students with marks less than 45 in any subject.

I want to know if there is any Dataweave method that can simplify this operation for me?

Thanks in Advance.

Upvotes: 2

Views: 155

Answers (1)

machaval
machaval

Reputation: 5059

Hi have you tried some from dw::core::Arrays you can see the docs. It will return true if at least one matches with your condition.

Upvotes: 3

Related Questions