Skip to content

Commit

Permalink
feat: add includes for the fp package
Browse files Browse the repository at this point in the history
  • Loading branch information
Parham Alvani committed Dec 27, 2023
1 parent 86aa88a commit 8caacb2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/fp/array.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fp

func Includes[T comparable](item T, items []T) bool {
for _, i := range items {
if item == i {
return true
}
}

return false
}
24 changes: 24 additions & 0 deletions pkg/fp/array_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fp_test

import (
"testing"

"github.com/kaytu-io/kaytu-util/pkg/fp"
"github.com/stretchr/testify/require"
)

func TestIncludesWithStrings(t *testing.T) {
require := require.New(t)

require.True(fp.Includes("Parham", []string{"Parham", "Perham"}))
require.True(fp.Includes("Perham", []string{"Parham", "Perham"}))
require.False(fp.Includes("Hassan", []string{"Parham", "Perham"}))
}

func TestIncludesWithNumbers(t *testing.T) {
require := require.New(t)

require.True(fp.Includes(1373, []int{1378, 1373}))
require.True(fp.Includes(1378, []int{1378, 1373}))
require.False(fp.Includes(1372, []int{1378, 1373}))
}

0 comments on commit 8caacb2

Please sign in to comment.