Skip to content

Commit

Permalink
refactored reducer for efficiency and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 7, 2024
1 parent 5fe0f72 commit f3d40a2
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/org/rascalmpl/library/List.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down

0 comments on commit f3d40a2

Please sign in to comment.