From 42e8a43375df044b49ec7ba5f4dbc674ee94bd3f Mon Sep 17 00:00:00 2001 From: ziggie Date: Fri, 4 Oct 2024 00:32:27 +0200 Subject: [PATCH] fn: Add Size and IsEmpty methods to Set --- fn/set.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fn/set.go b/fn/set.go index 51368b210..c3a326470 100644 --- a/fn/set.go +++ b/fn/set.go @@ -31,6 +31,16 @@ func (s Set[T]) Contains(e T) bool { return ok } +// IsEmpty returns true if the set is empty. +func (s Set[T]) IsEmpty() bool { + return len(s) == 0 +} + +// Size returns the number of elements in the set. +func (s Set[T]) Size() uint { + return uint(len(s)) +} + // Diff returns the difference between two sets. func (s Set[T]) Diff(other Set[T]) Set[T] { diff := make(Set[T])