// Comprehensive test combining all new functional programming features io.out "=== Comprehensive Feature Test ==="; // Example: Processing student data with advanced functional programming // Sample student data students : [ {name: "Alice", scores: [85, 92, 78, 90]}, {name: "Bob", scores: [75, 88, 82, 79]}, {name: "Charlie", scores: [95, 96, 94, 97]}, {name: "Diana", scores: [65, 70, 68, 72]} ]; // Calculate average score calculateAverage : scores -> with ( total : reduce (acc x -> acc + x) 0 scores; count : length scores; ) -> total / count; // Process each student using flatMap and array operations processStudent : student -> with ( scores : student.scores; average : calculateAverage scores; cumulative : cumsum scores; // Use pattern guards to assign grades grade : when average is a if (a >= 90) then "A" a if (a >= 80 and a < 90) then "B" a if (a >= 70 and a < 80) then "C" a if (a >= 60 and a < 70) then "D" a if (a < 60) then "F" _ then "Invalid"; // Use broadcasting to normalize scores maxScore : reduce (acc x -> math.max acc x) 0 scores; normalized : broadcast (score max -> score / max * 100) maxScore scores; ) -> { name: student.name, average: average, grade: grade, cumulative: cumulative, normalized: normalized }; // Process all students processedStudents : map processStudent students; io.out "Processed Students:"; io.out processedStudents; // Advanced analysis using array programming io.out "=== Advanced Analysis ==="; // Extract all scores using flatMap allScores : flatMap (s -> s.scores) students; io.out "All scores:"; io.out allScores; // Find top performers using where and at highScoreIndices : where (score -> score >= 90) allScores; highScores : at highScoreIndices allScores; io.out "High scores (>=90):"; io.out highScores; // Use zipWith to compare consecutive students studentNames : map (s -> s.name) processedStudents; studentAverages : map (s -> s.average) processedStudents; // Reshape data into matrix for analysis scoresMatrix : reshape [4, 4] allScores; io.out "Scores as 4x4 matrix:"; io.print scoresMatrix; // Combine multiple operations in a pipeline topStudents : filter (s -> s.average >= 85) processedStudents; topStudentAnalysis : sort.by topStudents (s -> s.average); io.out "Top students (avg >= 85), sorted by average:"; io.out topStudentAnalysis; io.out "=== All comprehensive tests completed ===";