Closed thedevsaddam closed 3 weeks ago
lo
contains lo.Contains
already. ^_^
lo.Contains :: func[T comparable](collection []T, element T) bool
Since go1.21, stdlib slices
is added and it contains Contains
, too.
slices.Contains :: func[S ~[]E, E comparable](s S, v E) bool
https://godoogle.sonion.xyz/search?q=%5BT+comparable%5Dfunc%28collection+%5B%5DT%2C+needle+T%29+bool
Thank you for the feedback! Given that similar functionality already exists, I'll go ahead and close this PR. I appreciate the insights!
Introduce
In
function for element existence check in a collectionChecks if an element exists in the collection. It returns true if the element is found; otherwise, false.
The
In
function offers several advantages:In
function explicitly states its purpose of checking for element existence, making the code easier to understand.In
function returns immediately upon finding the first match, while the Count function iterates through the entire collection even if it finds a match early. This can lead to unnecessary iterations, especially in large collectionsIn
function returns a boolean, which is a straightforward answer to the question of whether the element exists. In contrast, Count returns a count, which is more information than needed for a simple existence check.