Download or view groupBy.frink in plain text format
/** This implements a "groupBy" function. The function is applied to each
member of list, returning a value y for each. The results are grouped in a
dictionary where the key is the value produced by the function and the
value is an array of items from the list that returned that value y, in the
order they were encountered in the list.
*/
groupBy[list, func] :=
{
result = new dict
for item = list
result.addToList[func[item], item]
return result
}
// println[groupBy[1 to 15, {|x| x mod 3}]]
Download or view groupBy.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 20293 days, 11 hours, 9 minutes ago.