Skip to content

v2.5.0

Compare
Choose a tag to compare
@elliotchance elliotchance released this 27 Feb 15:33
· 11 commits to master since this release
42749e4
Add GroupBy (#189)

GroupBy groups slice elements by key returned by getKey function for each
slice element.

It returns a map in which slices of elements of original slice are matched
to keys defined by getKey function. It returns non-nil map, if empty or nil
slice is passed.

For example, if you want to group integers by their remainder from division
by 5, you can use this function as follows:

	_ = pie.GroupBy(
	    []int{23, 76, 37, 11, 23, 47},
	    func(num int) int {
	        return num % 5
	    },
	)

In above case map {1:[76, 11], 2:[37, 47], 3:[23, 23]} is returned.

Fixes #188