github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/sets/readset/wrapper.go (about)

     1  package readset
     2  
     3  import (
     4  	"github.com/djordje200179/extendedlibrary/datastructures/iter"
     5  	"github.com/djordje200179/extendedlibrary/datastructures/sets"
     6  )
     7  
     8  // Wrapper is a wrapper around a Set that provides read-only access to it.
     9  type Wrapper[T any] struct {
    10  	set sets.Set[T]
    11  }
    12  
    13  // From creates a new Wrapper around the given Set.
    14  func From[T any](set sets.Set[T]) Wrapper[T] {
    15  	return Wrapper[T]{set}
    16  }
    17  
    18  // Size returns the number of elements in the Set.
    19  func (w Wrapper[T]) Size() int {
    20  	return w.set.Size()
    21  }
    22  
    23  // Contains returns true if the Set contains the given value.
    24  func (w Wrapper[T]) Contains(value T) bool {
    25  	return w.set.Contains(value)
    26  }
    27  
    28  // Clone returns a shallow copy of the Set.
    29  func (w Wrapper[T]) Clone() Wrapper[T] {
    30  	clonedSet := w.set.Clone()
    31  	return Wrapper[T]{clonedSet}
    32  }
    33  
    34  // Iterator returns an iter.Iterator over the Set.
    35  func (w Wrapper[T]) Iterator() iter.Iterator[T] {
    36  	return w.set.Iterator()
    37  }
    38  
    39  // Stream streams the elements of the Set.
    40  func (w Wrapper[T]) Stream(yield func(T) bool) {
    41  	w.set.Stream(yield)
    42  }