From fb1437cb6da60c99a37e745bf50b8b819bec7a88 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Fri, 26 Apr 2024 18:52:40 -0700 Subject: [PATCH] fn: add Elem function for set membership --- fn/slice.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fn/slice.go b/fn/slice.go index 8f55cc159..22f3fa6f5 100644 --- a/fn/slice.go +++ b/fn/slice.go @@ -114,6 +114,11 @@ func FindIdx[A any](pred Pred[A], s []A) Option[T2[int, A]] { return None[T2[int, A]]() } +// Elem returns true if the element in the argument is found in the slice +func Elem[A comparable](a A, s []A) bool { + return Any(Eq(a), s) +} + // Flatten takes a slice of slices and returns a concatenation of those slices. func Flatten[A any](s [][]A) []A { sz := Foldr(