-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add includes for the fp package
- Loading branch information
Parham Alvani
committed
Dec 27, 2023
1 parent
86aa88a
commit 8caacb2
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})) | ||
} |