Skip to content

Commit fb1437c

Browse files
committed
fn: add Elem function for set membership
1 parent 9c30bce commit fb1437c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fn/slice.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ func FindIdx[A any](pred Pred[A], s []A) Option[T2[int, A]] {
114114
return None[T2[int, A]]()
115115
}
116116

117+
// Elem returns true if the element in the argument is found in the slice
118+
func Elem[A comparable](a A, s []A) bool {
119+
return Any(Eq(a), s)
120+
}
121+
117122
// Flatten takes a slice of slices and returns a concatenation of those slices.
118123
func Flatten[A any](s [][]A) []A {
119124
sz := Foldr(

0 commit comments

Comments
 (0)