From f3d40a2caa210bb84048b3cf535c6eac74e5e4c0 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 7 Nov 2024 19:35:46 +0100 Subject: [PATCH] refactored reducer for efficiency and documentation --- src/org/rascalmpl/library/List.rsc | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/org/rascalmpl/library/List.rsc b/src/org/rascalmpl/library/List.rsc index 6987afbba93..03f6fecf6a6 100644 --- a/src/org/rascalmpl/library/List.rsc +++ b/src/org/rascalmpl/library/List.rsc @@ -491,14 +491,7 @@ int add(int x, int y) { return x + y; } reducer([10, 20, 30, 40], add, 0); ``` } -&T reducer(list[&T] lst, &T (&T, &T) fn, &T unit) -{ - &T result = unit; - for(&T elm <- lst){ - result = fn(result, elm); - } - return result; -} +&T reducer(list[&T] lst, &T (&T, &T) fn, &T unit) = (unit | fn(it, elm) | elm <- lst); list[&T] remove(list[&T] lst, int indexToDelete) = [ lst[i] | i <- index(lst), i != indexToDelete ];