Documentation
¶
Index ¶
- type Set
- func (set Set[T]) Add(items ...T) Set[T]
- func (set Set[T]) All(f func(v T) bool) bool
- func (set Set[T]) Any(f func(v T) bool) bool
- func (set Set[T]) Clone() Set[T]
- func (set Set[T]) Contains(item T) bool
- func (set Set[T]) Count(f func(v T) bool) int
- func (set Set[T]) Difference(other Set[T]) Set[T]
- func (set Set[T]) Equal(other Set[T]) bool
- func (set Set[T]) Filter(f func(v T) bool) Set[T]
- func (set Set[T]) FilterFalse(f func(v T) bool) Set[T]
- func (set Set[T]) For(f func(v T) error) error
- func (set Set[T]) Intersection(other Set[T]) Set[T]
- func (set Set[T]) IsProperSubset(other Set[T]) bool
- func (set Set[T]) IsProperSuperset(other Set[T]) bool
- func (set Set[T]) IsSubset(other Set[T]) bool
- func (set Set[T]) IsSuperset(other Set[T]) bool
- func (set Set[T]) Len() int
- func (set Set[T]) Remove(items ...T) Set[T]
- func (set Set[T]) SymmetricDifference(other Set[T]) Set[T]
- func (set Set[T]) Union(other Set[T]) Set[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
func Map ¶
func Map[T, U comparable](set Set[T], mapper func(v T) U) Set[U]
Map converts all items in the set by using the mapper.
func (Set[T]) All ¶
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/hi/sets"
)
func main() {
s := sets.New(1, 2, 3, 4, 5)
fmt.Println(s.All(func(v int) bool { return v > 0 }))
fmt.Println(s.All(func(v int) bool { return v > 3 }))
fmt.Println(s.Any(func(v int) bool { return v > 5 }))
}
Output: true false false
func (Set[T]) Any ¶
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/hi/sets"
)
func main() {
s := sets.New(1, 2, 3, 4, 5)
fmt.Println(s.All(func(v int) bool { return v > 0 }))
fmt.Println(s.Any(func(v int) bool { return v > 3 }))
fmt.Println(s.Any(func(v int) bool { return v > 5 }))
}
Output: true true false
func (Set[T]) Count ¶
Count returns the number of elements that f returns true.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/hi/sets"
)
func main() {
s := sets.New(1, 2, 3, 4, 5)
cnt := s.Count(func(v int) bool { return v > 3 })
fmt.Println(cnt)
}
Output: 2
func (Set[T]) Difference ¶
Difference returns a new set with items that are included by the set but not the other.
func (Set[T]) Filter ¶
Filter returns a new subset where f returns true for.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/hi/sets"
)
func main() {
s := sets.New(1, 2, 3, 4, 5)
u := s.Filter(func(v int) bool { return v > 3 })
for v := range u {
fmt.Println(v)
}
}
Output: 4 5
func (Set[T]) FilterFalse ¶
FilterFalse returns a new subset where f returns false for.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/hi/sets"
)
func main() {
s := sets.New(1, 2, 3, 4, 5)
u := s.FilterFalse(func(v int) bool { return v > 3 })
for v := range u {
fmt.Println(v)
}
}
Output: 1 2 3
func (Set[T]) For ¶
For calls the f for each items in the set. If the f returns an error, For stops the iteration and return the error.
func (Set[T]) Intersection ¶
Intersection returns a new set with items that are included by both of the set and the other.
func (Set[T]) IsProperSubset ¶
IsProperSubset reports whether the set is a proper subset of the other.
func (Set[T]) IsProperSuperset ¶
IsProperSuperset reports whether the set is a proper superset of the other.
func (Set[T]) IsSuperset ¶
IsSuperset reports whether the set is a superset of the other.
func (Set[T]) SymmetricDifference ¶
SymmetricDifference returns a new set.