Skip to content

Commit bfac048

Browse files
authored
Updating Count function (#36)
* Adding some new funky functions which I find useful Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions Created the Join, JoinProjection, Range, SumMap, Zip functions, ecah fuction is documented with how it works and had a unit test or maybe more * Added in an OrderBy function * Documentation comment for OrderBy which I missed out * Adding a Unit test for JoinProject function Updated the comments on the Join & OrderBy functions so they make a little more sense. Covered an extra test case with the Join test, where the left set has more data than the right and so the Right handside array of the join is empty * Adding a count method to the package, so you can find out how many items in a slice satisfy and given condition * Updating count to work with any so you can count structs as well as basic types * Removing extra underscores
1 parent 541e707 commit bfac048

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

count.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package underscore
22

33
// Count returns the number of elements in the slice that satisfy the predicate.
44
// example: Count([]int{1,2,3,4,5}, func(n int) bool { return n%2 == 0 }) // 2
5-
func Count[T comparable](slice []T, predicate func(T) bool) int {
5+
func Count[T any](slice []T, predicate func(T) bool) int {
66
count := 0
77
for _, item := range slice {
88
if predicate(item) {

count_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package underscore
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"strings"
65
"testing"
6+
7+
"github.com/stretchr/testify/assert"
78
)
89

910
func Test_Count_Can_Count_Numbers(t *testing.T) {
@@ -21,7 +22,7 @@ type People struct {
2122
Gender string
2223
}
2324

24-
func Test_Count_Can_Count__People(t *testing.T) {
25+
func Test_Count_Can_Count_People(t *testing.T) {
2526
people := []People{
2627
{Name: "Andy", Age: 43, Gender: "M"},
2728
{Name: "Fred", Age: 33, Gender: "M"},

0 commit comments

Comments
 (0)